Page 1 of 1

Strings and SELECT

Posted: Thu Dec 19, 2002 5:08 pm
by Toneboy
Just undergoing a problem in selecting items from my banners table in my MySql database.

The basic idea is to set an expiry time on a banner, so it isn't shown after a certain date. However this isn't working:
$timenow = time();
$sql = "SELECT * from banners WHERE b_mark = 0 and expiry > '$timenow'";
Whereas in testing (via php MyAdmin) with a typical timestamp it seems to work, e.g.:
SELECT * from banners WHERE b_mark = 0 and expiry > 1040338484
Is there some problem with using strings in a SELECT request?

Posted: Fri Dec 20, 2002 8:12 am
by Rob the R
I would try it without the single quotes around $timenow:

Code: Select all

$sql = "SELECT * from banners WHERE b_mark = 0 and expiry > $timenow";
Since "expiry" is numeric in the database, you shouldn't test it against a string. Leaving the single quotes off means you'll be comparing the number in $timenow to "expiry".

If this doesn't work, try echoing the $sql value. Do you get the same thing that you have successfully tested in phpMyAdmin?