Flash animation
// November 12th, 2008 // No Comments » // Flash
This is the first flash animation I did. It was a project for the school of the built environment back in 2003 I think.
Quick and dirty query generator
// November 12th, 2008 // No Comments » // PHP
Again, I needed to quicky put in WHERE and ANDs depending on how many parameters were submitted.
Instead of putting multiple conditionals, I just put them into an array:
$sqlarray = array();
if($year)
$sqlarray[] = "(table.Year = " . $year . ")";
if($week)
$sqlarray[] = "(table.Week = " . $week . ")";
if($otherparameter)
$sqlarray[] = "(otherparam = '" . $otherparam . "')";
$sql = "";
if(sizeof($sqlarray) > 0)
{
$sql = " WHERE ";
for($i = 0; $i < sizeof($sqlarray); $i++)
{
$sql = $sql . $sqlarray[$i];
if($i != sizeof($sqlarray) - 1)
$sql = $sql . " AND ";
}
}
SQL – Counting Occurrances of a String
// October 14th, 2008 // No Comments » // SQL
SELECT DISTINCT person, sum(CASE WHEN Field1 = 'String1' THEN 1 ELSE 0 END) AS [Field 1], sum(CASE WHEN Field2 = 'String2' THEN 1 ELSE 0 END) AS [Field 2], sum(CASE WHEN Field3 = 'String3' THEN 1 ELSE 0 END) AS [Field 3], sum(CASE WHEN Field4 = 'String4' THEN 1 ELSE 0 END) AS [Field 4], sum(CASE WHEN Field5 = 'String5' THEN 1 ELSE 0 END) AS [Field 5] FROM tblYourTable GROUP BY person
Inserting a Space Before a Capital Letter
// October 14th, 2008 // No Comments » // PHP
I needed to insert a space between a camel case string, however, some of the strings contained more than one uppercase letter. I needed to have a regular expression that inserted a space only after an uppercase letter that had a lowercase letter following it. Here is the code:
1 2 3 4 5 | //put space after uppercase $string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string); //put space before uppercase following lowercase $string = preg_replace('/([a-z])([A-Z])/', '\\1 \\2', $string); |
Incrementing date
// October 14th, 2008 // No Comments » // PHP
$date = date("Y-m-d");
for($day = 0; $day < 5;$day++)
{
echo date("jS F",strtotime($date));
$date = date("jS F",strtotime($date) + 86400);
}
Sorting Specific Array
// October 13th, 2008 // 1 Comment » // PHP
I needed to dynamically load a group of options from the database. The thing was that these were not organised alphabetically; instead they were ordered in platinum, gold, silver, bronze format. This posed a little bit of a problem. The way around it was seeting up an array with the correct order of options. Then query the DB and bring back the results. Looping through these results and getting the array key of the organised array. A new array created stores the options from the db, and is sorted on its keys with ksort.
$orderedarr = array(
0 => “platinum”,
1 => “gold”,
2 => “silver”,
3 => “bronze”);
$rsCustomerStatus = $db->query(”SELECT DISTINCT ProspectStatus
FROM tblFleetCustomer
WHERE (ProspectStatus IS NOT NULL) AND (ProspectStatus <> ”) ORDER BY ProspectStatus DESC”,1);
$displayarr = array();
foreach($rsCustomerStatus as $rowStatus)
{
//put the value in the correct position in array
$valarr = array_keys($orderedarr, strtolower($rowStatus["ProspectStatus"]));
$displayarr[$valarr[0]] = $rowStatus["ProspectStatus"];
}
ksort($displayarr);
//display array in correct order
foreach($displayarr as $val)
echo “<option value=\”". $val .”\”>”. htmlentities(ucwords(strtolower($val))) . “</option>\r\n”;
Spool in Oracle
// September 24th, 2008 // No Comments » // Database, Oracle
Spool prints out the current terminal text to a file
SQL> Spool on
SQL> set heading off <===
SQL> Spool c:\spooltext.txt
SQL> your_Query
SQL> Spool off
XML Entities
// September 23rd, 2008 // No Comments » // XML
For a project I was working on we needed to reuse a fair chunk of XHTML within an XML file, the best way around this was to use a custom entity.
<?xml version="1.0"?> <!DOCTYPE vehicles [ <!ENTITY tabdata "<p>XHTML content goes here</p>"> ]> <vehicles> <vehicle>&tabdata;</vehicle> </vehicles>
Flash Animated Banners
// September 7th, 2008 // No Comments » // Flash
This was a project I worked on quite a while back for Daz Citrus Blast. They wanted three different types of banner ad.
The graphics were originally created in Photoshop – I then had the task to recreate as much as possible in order to minimise file size.
The flame effect is what really adds to these banners. A “flame” movie clip was duplicated many times randomly.
