Jump to content

MySQL Re-Ordering


ibinod

Recommended Posts

I have a menu table which contains column like this

   

id

       

name

       

link

       

position

       

   

1

       

Home

       

home.php

       

1

       

   

2

       

About

       

about.php

       

2

       

   

3

       

Contact

       

contact.php

       

3

       

   

4

       

Faq

       

faq.php

       

4

       

   

5

       

Message

       

msg.php

       

5

       

   

6

       

Downloads

       

down.php

       

6

       

 

now let's say i want to change the position column value to 2 of id column that has id 1 and at the same time i want to change the position column value to 1 which has position value 1

can you pls suggest me how do i do this using php

 

using mysql i was able to do like this but pls suggest me a better way to do it using php

UPDATE menu SET position = 1 WHERE id = 2;
UPDATE menu SET position = 2 WHERE position = 1;

 

Link to comment
https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/
Share on other sites

As far as I can tell, this

 

UPDATE menu SET position = 1 WHERE id = 2;
UPDATE menu SET position = 2 WHERE position = 1;

 

will in end give you two rows with position = 2

 

For samples of sending queries to MySQL from php see mysql_query or preferably mysqli_query()

Link to comment
https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687583
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.