ibinod Posted November 10, 2008 Share Posted November 10, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/ Share on other sites More sharing options...
Boo-urns Posted November 10, 2008 Share Posted November 10, 2008 Are you going to be doing it often? I'm not an expert but you can do it through loops / switches if you're going to be updating a lot. I'm not sure what you're going for. Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-686966 Share on other sites More sharing options...
fenway Posted November 10, 2008 Share Posted November 10, 2008 Just re-save the new order Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687134 Share on other sites More sharing options...
ibinod Posted November 11, 2008 Author Share Posted November 11, 2008 Well this won't be done often cause it will be in the backend side of the site to rearrange the menus. can you pls provide me sample code using php to execute a such query Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687541 Share on other sites More sharing options...
Boo-urns Posted November 11, 2008 Share Posted November 11, 2008 If it won't be happening often when will it be happening? Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687543 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 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() Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687583 Share on other sites More sharing options...
Boo-urns Posted November 11, 2008 Share Posted November 11, 2008 If you use mysqli_query() is the best practice to still use sprintf and mysql_real_escape_string? I just found about mysqli_query() now. Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-687957 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 I never use sprintf() myself... just don't see use for it. You can use it if you wish. It doesn't really have anything to do with database. For mysqli extension there's mysqli_real_escape_string() Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-688100 Share on other sites More sharing options...
PFMaBiSmAd Posted November 11, 2008 Share Posted November 11, 2008 The second query was probably supposed to be - WHERE id = 1; Quote Link to comment https://forums.phpfreaks.com/topic/132110-mysql-re-ordering/#findComment-688103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.