0

So, after creating the field, the code and what else was needed to retrieve news order as mentioned here: Planning news ordering system

I have encountered another dilemma:

  • Having row X with order value 17 and row Y with order value 19, which is the best way to interchange their values for mysql with php code?

UPDATE

My meaning of interchange is: change a value with another.

What I am trying to achieve is similar as joomla does the sorting for its data. http://awesomescreenshot.com/01658u06e

sn_news table:

....   id     order   title  
       ====   =====   =======
       1231   1       ASDAASD
       1331   2       ASDXXSD
       1221   3       ASDBBSD
       1731   4       ASDYYSD
       1531   5       ASDCCSD

I want to swap id 1221's order 3 with the order 5 from id 1531 so it would become:

....   id     order   title  
       ====   =====   =======
       1231   1       ASDAASD
       1331   2       ASDXXSD
 -->   1221   5       ASDBBSD
       1731   4       ASDYYSD
 -->   1531   3       ASDCCSD
Community
  • 1
  • 1
Alex
  • 7,538
  • 23
  • 84
  • 152
  • What do you mean by interchanging values? Do you want to rename these two columns? – Daan May 09 '12 at 14:46
  • 1
    Altering table and interchanging column name would be more beneficial and if you still want to change values then you will need one more column.If you really want then i can tell you –  May 09 '12 at 14:59
  • ok, question updated with more info.... meanwhile I'm reading: http://stackoverflow.com/questions/37649/swapping-column-values-in-mysql and http://www.microshell.com/database/sql/swap-values-in-2-rows-sql/ – Alex May 09 '12 at 15:04

1 Answers1

1

It's the best i can understand

Update table_name set order=5 where id=1221;
Update table_name set order=3 where id=1531;
  • That's what I thought of too, at first, but I'm not so sure it is a good way of doin it – Alex May 09 '12 at 15:10