[SOLVED] strttome subracting seconds

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

[SOLVED] strttome subracting seconds

Post by Burrito »

I have this query:

Code: Select all

$getparts = mysql_query("select * from chatusers where room = '".mysql_escape_string($_GET['room'])."' and lasttime > ".strtotime("-10 seconds"));
but it's returning a bunch of rows when there really should only be 2 users who are within the 10 second range...can strtotime subract seconds?

Edit:
major brain fart on my part...I've revised my query to this:

Code: Select all

$partsqu = "select * from chatusers where room = '".mysql_escape_string($_GET['room'])."' and lasttime > '".date("Y-m-d H:i:s", strtotime("-10 seconds")."'");
but now I"m getting an error in my sql syntax ?? :S

Edit2: duh...another brain fart...I'm all good now...pretend this was never posted.

Burr
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: strttome subracting seconds

Post by RobertGonzalez »

Code: Select all

$partsqu = "select * from chatusers where room = '".mysql_escape_string($_GET['room'])."' and lasttime > '".date("Y-m-d H:i:s", strtotime("-10 seconds")."'");
Why not change your WHERE clause to:

Code: Select all

... and lasttime > " . time() - 10 . " ...
This should make it a little cleaner.
Post Reply