DaveNZ Posted August 29, 2010 Share Posted August 29, 2010 Hi, I'm trying to select a field in the last row in my database and compare it to another value in an if statement, but I can't get it to work. I have $yesterday=date("d M Y", time()-86400); $lastRowQuery = "SELECT Date FROM DailyWxData ORDER BY Day DESC LIMIT 0,1"; $lastRowResult = mysql_query($lastRowQuery,$link); if ($lastRowResult != $yesterday) { $output = "yesterday's data is not in the database"; } else { $output = "yesterday is in the database"; } After this code is executed I get $output = "yesterday's data is not in the database"; The value $yesterday has taken is "27 Aug 2010" The last row of the database has "27 Aug 2010" in the Date field Also note that Day is like an auto number field (ie first row has value 1, 250th row has value 250) Can anyone see what I'm doing wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/211980-select-last-row-of-mysql-database/ Share on other sites More sharing options...
sohaibshaheen Posted August 29, 2010 Share Posted August 29, 2010 Hey, I am new to this..but your problem seems simple... What you need to do is $lastRowResult = mysql_query($lastRowQuery,$link); $lastrowarray=mysql_fetch_array($lastRowResult); if ($lastrowarray['Date'] != $yesterday) { $output = "yesterday's data is not in the database"; } else { $output = "yesterday is in the database"; } Quote Link to comment https://forums.phpfreaks.com/topic/211980-select-last-row-of-mysql-database/#findComment-1104750 Share on other sites More sharing options...
DaveNZ Posted August 29, 2010 Author Share Posted August 29, 2010 Thank you, it worked!! Quote Link to comment https://forums.phpfreaks.com/topic/211980-select-last-row-of-mysql-database/#findComment-1104761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.