Jump to content

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

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.