PDA

View Full Version : mysql & cgi help!


tariqf
02-10-2003, 10:39 PM
Hi everyone I'm just stating to use mysql & cgi and I have a problem. I have a script that outputs a list of rows into a spreadsheet ordered by time and I need them putting into hourly groups, i.e. with a space seperating each hours results. I can't work out the best way do do this can anyone give me a clue? The code is attached to give you an idea of what I mean.

Is there a mysql command or should I use perl to separate out the hours?

ian17
02-14-2003, 10:37 AM
Tariqf,
That's a long attachment to trawl through, I didn't look closely at all you're doing there. But it seems to me that the best place to create spaces is by using perl, inside the
"while ( @data = $sth1->fetchrow_array() )"
loop.

Before entering that loop, create a variable $hour_of_day, initially zero.

Inside the loop, compare it with the hour extracted from savetime and if different, save the new hour in $hour_of_day and create an empty worksheet row with a $newsheet->write(++$row).

That should give you a blank row every time the hour changes.

How the get the hour out of savetime depends on its format. If savetime uses the mysql time format you can extract the hour from it by adding 'hour(savetime)' into the SQL statement. If it's tacked on after the variable 'site', you can get at it as $data[8]

If all this makes any sense to you, hope it helps.

Ian.

tariqf
02-14-2003, 05:37 PM
thanks for your help, i'll look into doingjust that