TheGallery Posted September 16, 2011 Share Posted September 16, 2011 Hello again community. My problem has 2 parts. The first part is about the best method to solve it, and the second part is the method i have chosen and some problems that occured. I have a database that stores usernames and tracks their visits in the website. I want to make a page that will show the users either alphabeticaly or by visits. The first question is, what's the best method of sorting them (depending on the choice), should i store them in an array (with the username as key and the visits as value) or i should send commands to sort the database. The question may be stupid but i've heard about database sorting, i don't know if it's for such occasions though. If there is a different, even better way to display the data i'd like to hear it I have chosen to store the data in an array, with the usernames as key and the visits as values. I know how to sort arrays according to keys or values, but i need to display the usernames and i don't know how to display the keys Oo. Link to comment Share on other sites More sharing options...
Ingolme Posted September 16, 2011 Share Posted September 16, 2011 When you perform the SQL query, the ORDER BY clause will let you choose which field to sort the results by. If you want them reversed, add the DESC keyword. SELECT field1,field2 from table ORDER BY field1 SELECT fieldA,fieldA from table ORDER BY fieldB DESC Link to comment Share on other sites More sharing options...
TheGallery Posted September 16, 2011 Author Share Posted September 16, 2011 Oh, so the shorting only happens to the pulled data? It doesn't short the database every time it is executed? Link to comment Share on other sites More sharing options...
Ingolme Posted September 16, 2011 Share Posted September 16, 2011 The data in the database could be in any order, you can't make any assumptions. You only sort the data when you're retrieving it. Link to comment Share on other sites More sharing options...
TheGallery Posted September 16, 2011 Author Share Posted September 16, 2011 That was pretty easy Thanks a lot for the support once more. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.