|
-
Nov 3rd, 2006, 07:36 AM
#1
Thread Starter
Member
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.
-
Nov 3rd, 2006, 11:41 AM
#2
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.
-
Nov 6th, 2006, 03:46 AM
#3
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|