...

View Full Version : grab last row only in ascending results [RESOLVED]



tripwater
11-14-2006, 04:14 PM
I have a query I am running in Mysql that gets all notes and prints them on the page with the most recent note at the bottom of the page. So it goes from Date Added acending as you scroll down.

But at the very top of the page I have additional info and would like to print the latest note at the very top of the page. Just this one note so if they do not want to scroll down to read all the notes and are there to only read the latest note, it is at the top by itself.

Now I know I can call the same exact query as I do for the notes lower on the page but say order by dateadded desc limit 1. But I was hoping that instead, I could just grab the very last row from the result set I got in the notes query, print the note and then call @mysql_data_seek($result,0); to reset the result and then loop through my notes at the bottom to display all the notes.

So my question to you is this, is there a way to grab the last row from a query result by using mysql_num_rows() or something to get the last result in the array?

Thanks for any help with this. If I have to, I will just write another query.

Brandoe85
11-14-2006, 04:33 PM
Make sure you reset the result back to the first record afterwords, but I think it should work:
if(mysql_data_seek($result, mysql_num_rows($result) -1))
{
$lastRec = mysql_fetch_assoc($result);
}

good luck;

tripwater
11-14-2006, 05:04 PM
Thank you very much. That worked!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum