SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    Brisbane
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to reverse mySQL Query

    I have a database which only has 2 fields. (id, accuracy)

    I need to be able to reverse my database results to have them show correctly. The query is below:

    Code:
    $result = @mysql_query("SELECT * FROM track_record order by id DESC LIMIT 0,60");
    
    if (!$result) die('<p>Error performing query: ' . mysql_error() . '</p>');
    
        // Display the text
        while ( $row = mysql_fetch_array($result) ) {
    
          $id = $row['id'];
          $accuracy = $row['accuracy'];
    
          echo('<img border="0" src="_images/'.$accuracy.'" width="7" height="18">');
    
        }
    What do I need to do to make the results display in reverse order?

    Thanks

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    order by id ASC

    This does not seem very on topic for an Advanced PHP forum?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about ordering by id ascending rather than descending. Simple solution.

    James Carr, Software Engineer


    assertEquals(newXPJob, you.ask(officeOfTheLaw));

  4. #4
    SitePoint Member
    Join Date
    May 2003
    Location
    Brisbane
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would work in most cases. However I need to display the latest 60 results, hence the 'order by id DESC'

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as a quick hack
    PHP Code:
    $output = array();
        while ( 
    $row mysql_fetch_array($result) ) {

          
    $id $row['id'];
          
    $accuracy $row['accuracy'];

          
    $output[] = '<img border="0" src="_images/'.$accuracy.'" width="7" height="18">';

        }
    echo 
    implode("\n"array_reverse($output)); 
    not tested

  6. #6
    SitePoint Member
    Join Date
    May 2003
    Location
    Brisbane
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gotta love the quick hack.

    Thanks heaps... Problem solved.

    Only had to make one small change

    Dropped the /n out of this line

    echo implode("\n", array_reverse($output));

    Other than that...Perfect... Thanks again

    Craig


Bookmarks

Posting Permissions

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