Hello Friends.
How I can change the order of database items.
For example I have a table like this:
[text]Name Email
----------------------------
John john@ex.com
Peter peter@ex.com
Sam sam@ex.com[/text]
Now I want to change the order of this items. For example I want to change the above table to this:
[text]Name Email
----------------------------
Peter peter@ex.com
Sam sam@ex.com
John john@ex.com[/text]
How I can do this?
Thanks!
Change the order of database items
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Change the order of database items
Dump the data, re-order the array and re-insert. Alternatively, you can add a field, such as `offset` and in your scripts include an ORDER BY clause to effectively order your result set.
Cheers,
Alex
Cheers,
Alex
Re: Change the order of database items
Code: Select all
ALTER TABLE [table] ORDER BY eMail DESC- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Change the order of database items
Why not just order it when you select it?
[text]SELECT * FROM table_name ORDER BY Email DESC[/text]
[text]SELECT * FROM table_name ORDER BY Email DESC[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Change the order of database items
Thanks for your replies, friends.
I think that using 'ORDER BY' is the best way. It seems that there is no way to change item's order.
Any way, thanks for your helping! And sorry for my bad English!
I think that using 'ORDER BY' is the best way. It seems that there is no way to change item's order.
Any way, thanks for your helping! And sorry for my bad English!