loop out the results from a mysql query in reverse order

Discussion in 'PHP' started by relixx, Nov 13, 2006.

  1. #1
    Man, I need more sleep. This is probably a very easy to solve solution, but for the life of me i cant figure it out

    I have the results of a mysql query, and after its been used I need to loop through the results in the reverse order.

    Im sure i could use a for statement, eg:

    for ($i=5; $i>=0; $i--) {
    find the row $i in the result
    spit it out
    }


    however, i cant remember how to seek a specific row in mysql and my google searches arent turning p much (lol, i dont think im able to read the pages properly)

    can somehow tell me how to go to a specific row in a result set? I used mysql_fetch_assoc, would i have to use another function?
     
    relixx, Nov 13, 2006 IP
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mysql_fetch_assoc fetches just one row so presumably to do whatever you did to the result you would have extracted each row and put it in an array.

    From there the for statement you have should work just fine.
     
    streety, Nov 13, 2006 IP
  3. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #3
    well, i actually dozed off at work and when i woke up it came to me in a flash of light (well, actually the flash of light was from my monitor going out of sleep mode, hahaha). mysql_data_seek was what i was trying to remember :)
     
    relixx, Nov 13, 2006 IP
  4. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Yeah; you have to remember that once it goes through the array, the cursor is in the last position.
     
    drewbe121212, Nov 13, 2006 IP