Jump to content

Latest SQL data...


fesan

Recommended Posts

Hi....

 

Is there a way to get the last row of a table and get the data out of just that row?

With PHP and MySQL....

 

I've tryed a simple way but it seams quite unstable:

 

$finn_refnr = "SELECT refnr FROM ${db_records}"; 
$result_refnr = mysql_query($finn_refnr) or die(mysql_error());
while($row = mysql_fetch_array($result_refnr)){
$new_refnr = $row['refnr'];
echo $new_refnr;
}

 

Sorry for my norwegianenglish and the norwegian typing in the script.

Link to comment
https://forums.phpfreaks.com/topic/44011-latest-sql-data/
Share on other sites

Order it by date or by a cumulative unique identifier, do you have any auto_increment fields?

 

$finn_refnr = "SELECT refnr FROM $db_records ORDER by "auto_increment field here" DESC LIMIT 0,1  ";

 

That will order the query by the most recent, and limit the number of results to 1. To give you the exact query i'd need to know what fields are in your database and what they do.

Link to comment
https://forums.phpfreaks.com/topic/44011-latest-sql-data/#findComment-213693
Share on other sites

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.