Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2006, 03:14 PM   PM User | #1
tripwater
Regular Coder

 
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
tripwater is an unknown quantity at this point
grab last row only in ascending results [RESOLVED]

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.

Last edited by tripwater; 11-14-2006 at 04:05 PM..
tripwater is offline   Reply With Quote
Old 11-14-2006, 03:33 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
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;
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 11-14-2006, 04:04 PM   PM User | #3
tripwater
Regular Coder

 
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
tripwater is an unknown quantity at this point
Thank you very much. That worked!
tripwater is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:24 AM.


Advertisement
Log in to turn off these ads.