• Log in or sign up for an account here: https://www.sythe.org/login

PHP/SQL Time Issues...

i am java

Active Member
Joined
Apr 9, 2008
Sythe Gold
0
Messages
231
OK, so a friend of mine was bored, so I told him to write me a small, simple script. For some reason, the script doesn't seem to work still. I honestly can't figure it out, and we are both pretty good PHP programmers.

Code:
$sql="SELECT * FROM `test` WHERE `testm`-".date("U")."<5 ORDER BY `testm` DESC";

Now, for some reason, it doesn't just select the times from 5 seconds ago (which is the time I am using to simply test the script ATM), it selects everything in the table.

Anyone got any ideas?
 
I think it has to do with you using double quotes in the middle of the query when the whole query is also surrounded by double quotes. I'm kind of surprised it works I would think that they need to be escaped but I haven't done much work with SQL.
 
I had the current time and the time in the DB mixed up, so when I would subtract the current time by the time in the DB, it would give me negative numbers. Thus, when it was selecting the users from the DB, it was selecting everyone because everyone's last activity was in the negatives. (IE, less than 5.)

The simple solution? I replaced

`testm`-".date("U")."<5

with

".date("U")."-`testm`<5
 
Runescape Gamblingrunescape gambling
Back
Top