Results 1 to 21 of 21

Thread: reversing row order

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    reversing row order

    hey

    PHP Code:
        $sql "SELECT * FROM announcement ORDER BY announcementid DESC LIMIT $num, 5";
            
    $result mysql_query($sql);
            
    $sql "SELECT * FROM " .  $result " ORDER BY announcementid ORDER BY ASC)"
    that doesnt work, i want to pick out the last 5 rows, and instead of them showing as 15-16-17-18-19-20, i want it go in reverse order, from 20 to 15.

    if i do "ASC" instead of desc in the first sql statement, it picks 1->5 instead, i tried nested statements too, didnt work. ideas?

    PHP Code:
    $sql="SELECT * FROM (SELECT * FROM announcement LIMIT $num, 5) ORDER BY announcementid ORDER BY ASC" 
    $num = number of rows - 5

    thanks
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312
    if you want it to display tyem you coudl try putting htem into an array backwards, then itll print them forwards
    Power to 2000 Electronic Donkeys!
    www.edonkey2000.com
    I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".

  3. #3
    New Member
    Join Date
    Jul 2002
    Location
    United States
    Posts
    2
    PHP Code:
    $sql "SELECT * FROM `announcements` ORDER BY `id` DESC LIMIT $num, 5"

  4. #4
    New Member
    Join Date
    May 2002
    Posts
    2
    how about making a virtual table with the ones selected...
    http://prog.proboards4.com/

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: reversing row order

    Originally posted by nabeels786
    PHP Code:
    $sql "SELECT * FROM " .  $result " ORDER BY announcementid ORDER BY ASC)"
    You don't need that second ORDER BY:

    PHP Code:
    $sql "SELECT * FROM " .  $result " ORDER BY announcementid ASC)"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    scoutt
    Guest
    ASC doesn't have any impact on what rows you get. it just puts them in the order.

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Well you can do the array thing that was suggested, or you can just get the number of records and subtract that by 5 to get your starting point.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    i tried everything suggested, nothing worked.


    hobo, thats what ive done, subtracted by 5, and use the limit to get the last 5, i want to reverse the last 5 it gives me
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    This works fine for me:

    PHP Code:
     $sql "SELECT * FROM table ORDER BY id DESC LIMIT 5"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    scoutt
    Guest
    why are you quering it twice? wouldn't this just work by itself

    PHP Code:
    $sql "SELECT * FROM announcement ORDER BY announcementid asc LIMIT $num, 5";
            
    $result mysql_query($sql); 

  11. #11

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    it gives me 5->1
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  12. #12

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    i dont know if it was the best way, but i stuck it into a for loop

    PHP Code:
        $num mysql_num_rows(mysql_query("SELECT * FROM announcement"));
        for(
    $i=1;$i<=5;$i++){
            
    $nnum=$num-$i;
            
    $sql "SELECT * FROM announcement LIMIT $nnum, 1";
            
    $result mysql_query($sql);
            while(
    $row mysql_fetch_array($result)){
                
    //its in order, output it how i want        
    }
        } 
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  13. #13
    scoutt
    Guest
    Originally posted by nabeels786
    it gives me 5->1
    what id you echo $result?

    if you use mysql_fetch_array() then it will do what you want.

  14. #14

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    yeah i always do mysql_fetch_array()

    the loop worked, i dunno why the other ones didnt
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  15. #15
    scoutt
    Guest
    Originally posted by nabeels786
    it gives me 5->1
    so are you saying that when you echo the row out the id is 5 and goes down to 1? isn't that what you want.

  16. #16
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    my last post still works for me...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  17. #17
    scoutt
    Guest
    I know that is the way I do it also. just can't see what he is doing that is doesn't work.

  18. #18
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    Iknow tha tis the way I do it also. just can't see what he is doing that is doesn't work.
    drinking again?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  19. #19

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    tried that, it gives me 15->20
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  20. #20
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by nabeels786
    tried that, it gives me 15->20
    dude, I'm sorry, but you must be doing something retarded, because my solution works when I try it, and I'm pretty sure what scoutt is trying works for him. Why don't you post all of your code, plus a save of your database, so we can make it work for you?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  21. #21
    scoutt
    Guest
    does it literrally print that out?

    so on the screen you see 15->20 or does it print

    ID
    ---
    15....
    16...
    17.....
    18.....
    19.....
    20.....

    isn't that what you want? if not just use DESC instead of ASC.

    Micheal you are confusing the bejesus out of me

Posting Permissions

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



Click Here to Expand Forum to Full Width