allowing site visitors to view info in any order
I'm a bit stuck on this one.
I've developed a site where a list of names and addresses are drawn from a MySQL database when a site visitor selects a page from a nav menu but I would like to be able to give them the choice of viewing the information in the order they want.
At the moment it is shown in order of the dynamically produced field number from the database but I'd like them to be able to view the results in order of Name or Zip code or whatever they like.
I've looked about and can't find any tutorials that cover this - does anyone have some pointers on this problem?
Your form will require an extra field possibly a drop down list where they can use this option to sort by:
Then you need to append your sql on what the selected. So ORDER BY date, ORDER BY ZipCode, ORDER BY name etc.
All the references I have don't use the term 'order' so am I being extra dumb or is there a different term used in PHP to tell the results to appear in a certain order....
I've now been looking into the 'sort' command and ensuring that my information is in arrays but the last step seems to be the tricky one, that I don't know how to bring in my dynamic information from the MySQL db into the array, rather than the static stuff I've been testing with.....
Are you using the sort function in PHP or are you trying to sort when you make the Query? The ORDER BY term would work if you wanted to sort the date as you got it from the database. Using the sort() function will do it after the fact. Both will work, personally I like doing it in the query...just looks a bit cleaner to me.
For getting the data you should be able to use mysql_fetch_row() or mysql_fetch_array() after you run the query. More information at the link below.
Hi Calash -
Thanks for the link.
I'm actually using the sort function in PHP, allowing the site visitor to view the list of results from MySQL and then, if they want, to view the results in the order they want to (i.e. by the $address field or the $postcode field).
I am probably trying to run before I can walk but I'm determined to offer this functionality on my site!
Last edited by disco_troll; 12-07-2004 at 04:59 PM.
Page generated in 1,394,375,372.25085 seconds with 19 queries