views:

74

answers:

1

This is part of my TV guide script:

       //Connect to the database
   mysql_connect("localhost","root","PASSWORD");
   //Select DB
   mysql_select_db("mytvguide");

   //Select only results for today and future
   $result = mysql_query("SELECT programme, channel, episode, airdate, expiration, setreminder FROM mediumonair where airdate >= now()");

The episodes show up, so there are no issues there. However, it's getting the database to find data that's the issue.

If I add a record for a programme that airs today this should show:

Medium   showing on TV4   8:30pm    "Episode"    Set Reminder
Medium  showing on TV4  May 18th - 6:25pm  "Episode 2"  Set Reminder
Medium  showing on TV4  May 18th - 10:25pm  "Episode 3"  Set Reminder
Medium  showing on TV4  May 19th - 7:30pm  "Episode 3"  Set Reminder
Medium  showing on TV4  May 20th - 1:25am  "Episode 3"  Set Reminder
Medium  showing on TV4  May 20th - 6:25pm  "Episode 4"  Set Reminder

but this shows instead:

    Medium  showing on TV4  May 18th - 6:25pm  "Episode 2"  Set Reminder
Medium  showing on TV4  May 18th - 10:25pm  "Episode 3"  Set Reminder
Medium  showing on TV4  May 19th - 7:30pm  "Episode 3"  Set Reminder
Medium  showing on TV4  May 20th - 1:25am  "Episode 3"  Set Reminder
Medium  showing on TV4  May 20th - 6:25pm  "Episode 4"  Set Reminder

I almost have the SQL working; just not sure what the right code is here, to avoid the second mistake showing - as the record (which indicates a show currently airing) does not seem to work at present.

Please can anyone help me with this?

Thanks

A: 

I don't know, but I would guess there's something strange about the way that you are storing your date and time in the airdate column. Try running a query like this so you can do the same comparison you're asking the database to do:

select now(), airdate from mediumonair where episode = 'Episode'
Don Kirkby
The airdate column is stored as DATETIME, so I don't understand why this happens.
whitstone86
You don't understand why what happens, @whitstone86 ? What does the result look like when you run the query I suggested?
Don Kirkby
I've got a blank area, no results.
whitstone86
It could be that the database server is storing the DATETIME based on Coordinated Universal Time (UTC), rather than local time. If there's enough difference, that would explain why the first row was missing from the retrieval.
Gilbert Le Blanc
http://i39.tinypic.com/mazec0.jpg shows an example of it
whitstone86
Please can someone help?
whitstone86
I suggest you look directly in the database to see how the airdate is stored. Do you have phpMyAdmin or some other database tool that can directly query your database? If you can't get that working, then using var_dump() to look at the query results would be the next best thing.
Don Kirkby
I do use phpMyAdmin for it, and it's stored as DATETIME.Tried setting timezone but had no luck with it.Will try var_dump() and let you know if it works!
whitstone86
Try using phpMyAdmin to run the query I posted. Then you can compare the stored airdate and the now() function yourself.
Don Kirkby