Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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;

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you very much. That worked!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •