Archive for March 2006
Script timezone
Because the Php version involved is pre 5.1.* I could not just add:
date.timezone = Africa/Harare
for example to the php.ini file and make all scripts use that timezone as default.
Neither could I use:
date_default_timezone_set('Africa/Harare');
and so the easiest option for me was to use:
putenv('TZ=Africa/Harare');
I just had to make sure that I put this statement in an include file that was available throughout the whole site (or the particular pages that required date and time). This was all good and fine until I
realised that the timestamp recorded in the MySql table was that for the server and not the one for the set timezone. I traced this to the insert query which was using something like this:
..."name = '$strName',timestamp = now(),"...
It realised that the time taken for the 'timestamp = now()' statement was for the MySql server time which is not affected by the the "putenv" command and therefore I changed the above to something like
$timestamp = date('Y-m-d H:i:s');
.."name = '$strName',timestamp = '$timestamp',"...
Now the date function gives the date and time from the timezone as set out in the "putenv" command.
OpenOffice Writer Thesaurus
Its not often that I use the Thesaurus menu but there are times when I just have to use it and
if its unavailable its a bit annoying.
MySQL equivalent of Top
So while for SQL server you would say:
select top 8 * from products
the equivalent of this in MySQL would be:
select * from products limit 8
Please note that limit can have two arguments, the first one
indicates the first row to return in the returned result set
and the other argument the maximum number of rows to return but
I will not discuss that in this posting.
Validating textboxes/combos
function ValidateField($strField,$strEntry, $intMin, $intMax){
if(trim($strEntry)=='' || strlen(trim($strEntry)) <$intMin || strlen(trim($strEntry))
> $intMax) {
echo "Please enter a $strField between $intMin and $intMax characters" ;
}
return true;
}
So say for a product textbox with a minimum length of 2 and maximum of 20 characters, I would validate like this:
ValidateField("Product",$strProduct, 2,20);
and then go on to the next one say product code:
ValidateField("Product Code",$strProductCode, 3,4);
and so on.