Jump to content

Select last row of mysql database


DaveNZ

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/211980-select-last-row-of-mysql-database/
Share on other sites

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.