Guardian-Mage Posted April 28, 2007 Share Posted April 28, 2007 $query2 = "SELECT shout_id FROM $database ORDER BY shout_id DESC"; //The above query selects all shout entries and lists them in reverse //order so the newest ones are first $result2 = mysql_query($query2) //Executes the SQL Query or die("This script was unable to execute the SQL Query #2. Please contact the webmaster and inform them of the problem. Sorry for the inconvience."); Now I need to take the last row from the above query and assign the value to the variable j for example, the results come back like this: 755 754 753 752 751 ... $j = "755"; I would want $j to equal 755 Link to comment https://forums.phpfreaks.com/topic/49124-solved-last-sql-query/ Share on other sites More sharing options...
Dragen Posted April 28, 2007 Share Posted April 28, 2007 can't you just put a limit on the mysql query, so it only gives you the one result? $query2 = "SELECT shout_id FROM $database ORDER BY shout_id DESC LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/49124-solved-last-sql-query/#findComment-240692 Share on other sites More sharing options...
snowdog Posted April 28, 2007 Share Posted April 28, 2007 $query2 = "SELECT shout_id FROM $database ORDER BY shout_id DESC"; //The above query selects all shout entries and lists them in reverse //order so the newest ones are first $result2 = mysql_query($query2) //Executes the SQL Query or die("This script was unable to execute the SQL Query #2. Please contact the webmaster and inform them of the problem. Sorry for the inconvience."); $show = mysql_fetch_object($result2); $j = $show->shout_id; That should do it. Snowdog Link to comment https://forums.phpfreaks.com/topic/49124-solved-last-sql-query/#findComment-240693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.