Jump to content

Order alphibeticaly


Arbitus

Recommended Posts

I can't figure out how to order the title of games when I select them out of the database and store them in an array. 

 

Database would look like

 

Halo 3

Final Fantasy

Alpha centari

 

which i need displayed as

 

Alpha Centari

Final Fantasy

Halo 3

 

please explain what is going on in code too (sort of oding this to learn more php)

Link to comment
https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/
Share on other sites

To explain it, the ORDER BY in a SQL statement will allow you to order the data like you want, you can order by a single column, as shown by gaza or by multiple columns as such:

 

$sql = "SELECT * FROM table_name ORDER BY name, title, year ASC";

 

So if there are 2 entries with the same name, it then orders by title if they have the same title it then orders by year etc. The next part is ASC or DESC you can sort it in Ascending order, 1-5 or descending order 5-1 depending on how you want the data.

 

Using order by instead of sorting the array will save on processing time and take a lot less toll on the cpu.

Link to comment
https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686772
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.