Strings and SELECT

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Toneboy
Forum Contributor
Posts: 102
Joined: Wed Jul 31, 2002 5:59 am
Location: Law, Scotland.
Contact:

Strings and SELECT

Post 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?
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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?
Post Reply