WEB Changing order rows in MySQL

Discussion in 'OT Technology' started by hurleyint1386, Aug 10, 2009.

  1. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    How can I change the order of rows in a table with out removing everything and recreating it? I know you'll say "Use the ORDER BY attribute" however it's a custom order than cannot be ordered by alphabetical order. Any easy way? everywhere I look, people say to use ORDER BY however it won't work for something custom. Thanks
     
  2. 2ofdem

    2ofdem OT Supporter

    Joined:
    Jun 17, 2003
    Messages:
    114,854
    Likes Received:
    8
    Location:
    aus.vic.mel
    Order it in the programming that gets the data.
     
  3. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    If I did that, it would take way too long. I just dropped the table and recreated it.


    /thread
     
  4. andrey

    andrey New Member

    Joined:
    Aug 12, 2006
    Messages:
    931
    Likes Received:
    0
  5. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    you're doing it wrong. the "order" of your DBs content should not matter, ever
     
  6. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    I agree, however in this situation, it was a very small table with only 6 rows, and I didn't want to sort it in the PHP. The order will never ever change, so it made things much easier.
     
  7. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    There is enough fail in here to go around!!
     
  8. Deviance

    Deviance Can't you smell that smell? OT Supporter

    Joined:
    Jul 10, 2007
    Messages:
    4,995
    Likes Received:
    12
    Location:
    Rocky Mountain High
    If these are pretty static and won't be changing much, I would have added a DisplayPosition field, ranked it how I wanted, then ordered on the new field. Then next time it had to be changed just modify the position in the database. But that's just me.

    Adding or changing positions in the display by deleting and re-adding the rows isn't really a scalable solution.
     
    Last edited: Aug 10, 2009
  9. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    This table will not be scalable. It is completely static. Although that is a good solution, adding an additional position field then ordering it by number and ordering it by that. But it wasn't too much trouble
     
  10. telc

    telc OT Supporter

    Joined:
    Aug 29, 2003
    Messages:
    18,580
    Likes Received:
    0
    Why didn't you create an ID column, give each one an ID based on the position you want it to me in, then:

    SELECT * FROM TABLENAME ORDER BY ID
     
  11. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    Please refer to above.
     

Share This Page