Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.