Arbitus Posted November 10, 2008 Share Posted November 10, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/ Share on other sites More sharing options...
gaza165 Posted November 10, 2008 Share Posted November 10, 2008 you can just use order by in the sql statement... $sql = SELECT * FROM table_name ORDER BY name ASC Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686768 Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 sql query would look like this: select column from table order by column as far as explaining the code...what code? Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686769 Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686772 Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 ASC is default sort order for ORDER BY so no need to explicitly state it. Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686790 Share on other sites More sharing options...
Arbitus Posted November 10, 2008 Author Share Posted November 10, 2008 thanks guys. thought it was something a little more complicated. I think i tried something like that. didn't think it would know to aphebetize instead of sort the numbers. Quote Link to comment https://forums.phpfreaks.com/topic/132146-order-alphibeticaly/#findComment-686836 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.