tucker Posted December 7, 2005 Share Posted December 7, 2005 I have 40 items listed in a database table...and I need to have items regularly change positions. Is there a way to shift the order of items in a database? Thank you. -Seth Quote Link to comment https://forums.phpfreaks.com/topic/3001-change-database-entry-order/ Share on other sites More sharing options...
ryanlwh Posted December 8, 2005 Share Posted December 8, 2005 you cannot shift the order physically in a table, but you could select the items in random order [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM yourtable ORDER BY rand() [!--sql2--][/div][!--sql3--] Quote Link to comment https://forums.phpfreaks.com/topic/3001-change-database-entry-order/#findComment-10081 Share on other sites More sharing options...
Zup Posted December 8, 2005 Share Posted December 8, 2005 If you really need to physically change the orders, you'll have to create a temporary table that has the same properties as the first table. Then you can insert data from the first table into the temporary table, select a row to be moved in the first table, and update the other row (the row that you put into the temporary table) with the information from the selected row. Now select your row from the temporary table, and update the row in the first table that you "moved". If that's too complicated to read, this may help: Let FTable be first table and TTable be temp. table We will switch rows 2 and 6. Row 2 from FTable gets copied into TTable. Row 6 in FTable overwrites Row2 in FTable (select then update) Row 2 from TTable overwrites Row 6 in FTable (select then update) TTable is deleted. End result: row 2 and row 6 are switched. Quote Link to comment https://forums.phpfreaks.com/topic/3001-change-database-entry-order/#findComment-10083 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.