tclogo



HotelsCombined.com

Pages

Archives

Categories


Recent Postings

Recent Comments

Feeds

RSS2 feed

Links

Most Popular Posts

Archive for March 2006

Script timezone

Friday, 31st March 2006 11:24pm
When you share the same timezone as your server then timezone setting for your scripts is no issue but for most of us this is not normally the case and once in a while you have to cater for some timezone. Lately I have been tackling the issue of getting the correct time  zone. I had to make sure that the timestamp recorded in the MySql database showed time in a particular 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.

delicious delicious | digg digg

Category: Php | Comments : 0

OpenOffice Writer Thesaurus

Monday, 27th March 2006 5:34am
Recently I decided to use OpenOffice 2.0 as my default office suite for all my word processing and spreadsheets requirements. All has been well until now I just have a small glitch that I have to resolve. Under the Tools/Language menu in the Writer application the 'Thesaurus' option is disabled and I can't seem to find how to enable it. I will have another look again at all the options available and if I can't find anything then maybe I will have to uninstall the application and then install it again carefully noting all the options that I use.


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.

delicious delicious | digg digg

Category: Open Source | Comments : 3

MySQL equivalent of Top

Thursday, 23rd March 2006 6:08am
How many times have I have tried to use a SQL server command in MySql and it has failed? Quite a few. This time the command involved was 'top'. Something you would normally use in SQL server like 'select top 8' doesn't work in MySQL but you should use the equivalent of 'top' which is 'limit'.


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.

delicious delicious | digg digg

Category: MySQL | Comments : 0

Validating textboxes/combos

Wednesday, 22nd March 2006 12:08pm
I have been working on a form where I have Php server side validation for field lengths for all the textboxes and combo boxes on a form. Normally I would have written a function for each of the textboxes but in this case there were 7 and so I had to think of a better way to do it. So I came up with this function:


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.

delicious delicious | digg digg

Category: Php | Comments : 0