Jump to content

Reorder MySQL rows via PHP?


Recommended Posts

Guest convention
I have a webpage that displays all of the MySQL rows in descending order. Though I don't know if this matters, all rows have a unique id number (auto_increment, primary key). I am wondering, is it possible to reorder any entry in MySQL in PHP (such as a form, GET, or any other method)? For example, move a row from the bottom of the page to, say somewhere in the middle?

I don't really want to do it by using the 'ORDER BY' SQL statement, but rather actually move the rows in the MySQL database.

Thank you for the help. :)
Link to comment
https://forums.phpfreaks.com/topic/25457-reorder-mysql-rows-via-php/
Share on other sites

Sorry, but that's just stupid. That's the whole purpose of the ORDER BY statement. If you have data that you want ordered in a specific way that cannot be achieved using ORDER BY then you should add a "sort" column to the data and then ORDER BY that.

And, the only way to reprder the rows would be to create a script that would overwrite all the records in the order you want. Again, bad idea.
perhaps you need to be a bit clearer.  Are you for instance, wanting to have a list of stuff that you want to be able to move up and down the list, such as, on a message board, having say 10 forums, and being able to move a forum up or down the list?

if so, then what you will want to do is create another field in your table called "layout_order" or other some such descriptive thing.  Then you will want to in your query, order by layout_order.  If you want to "bump" the item up a notch, then you would swap numbers with the it and the one above it. 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.