Page 1 of 1

Query Not Returning Correct Records

Posted: Sun Sep 26, 2004 1:18 pm
by Harlequin
Hi everyone.

This is the issue:

I have a variable: "$LastDownload" which is the last record in a table that identifies the last time a particular query was executed.

I also have a column in another table called "LastAction" which indicates the last time a user updated their information.

Both fields are Date/Time fields and capture the date in the following format:

Code: Select all

$Time = date("Y-m-d H:i:s");
For some reason, the following query returns ALL records though, even those whose LastAction Date is less than the $LastDownload date:

Code: Select all

// Select ALL Changed Records: 
   $UserDataQry = "SELECT * FROM MembersData 
   WHERE 'LastAction' > '$LastDownload' 
   ORDER BY UserID"; 
    $UserData = mysql_query($UserDataQry) or die("Error: " . mysql_error());
I'd appreciate any help you guys can offer here as I just can't seem to get the query right.

Posted: Sun Sep 26, 2004 1:34 pm
by feyd
it looks like LastAction is a string in your query, not a column reference.

Posted: Sun Sep 26, 2004 2:30 pm
by John Cartwright
you should use backticks for columns ... eg. `lastaction`

Posted: Sun Sep 26, 2004 3:06 pm
by Harlequin
Thanks very much Phenom

I knew I was missing something simple.

Would it be better syntactically if I used:

Code: Select all

WHERE ' . `LastAction` . ' > ' . $LastDownload . '
Instead of:

Code: Select all

WHERE `LastAction` > '$LastDownload'
I appreciate your help on this, been trying to get these CSV downloads automated properly for over a week and now t's done - thanks again mate 8)

Posted: Sun Sep 26, 2004 3:48 pm
by John Cartwright

Code: Select all

WHERE `LastAction` > '$LastDownload'
is fine..

you don't have to escape single quotes for variables in your queries

Posted: Sun Sep 26, 2004 3:52 pm
by Harlequin
:D Thanks again :D