-
Is this wrong???
Here is the code that I used and found not working.
$t=time();
$t-=84600;
$q="select * from flash where time>=".$t." order by time desc limit 10";
$result=mysql_query($q);
whts wrong with it???
The query returns all the rows in the table irrespective of the constraint.
:wave:
-
Re: Is this wrong???
why not just define $t as time() - 84600 in the first place?
try enclosing your variable in the query with single quotes, (ie: time>='" . $t . "') just to be safe. if that doesn't work, print the query out and see what it looks like, and make sure it runs in mysql itself or phpmyadmin and returns what you want. the query itself looks fine.
-
Re: Is this wrong???
If the "time" column is of type TIMESTAMP, DATE or DATETIME, it expects a MySQL timestamp value, not the Unix timestamp PHP uses. Try this:
Code:
$q="select * from flash where time>=FROM_UNIXTIME($t) order by time desc limit 10";
Note that variables in double-quoted strings are automatically replaced; no need to stop the string.
That said, the code is WRONG, WRONG, WRONG!!! It doesn't use parametrized queries and if you don't consistently use them, one day you'll write some SQL injection holes.