Printer Friendly Version
Email this thread to a friend
|
Featured Web Site Template |
|
Reflects user activity within the last 5 minutes
|
|
| Member |
Message |
leelee700
Joined: Oct 09, 2006
# Posts: 50
|
Posted: 05/26/2007 09:35 am
Hi everyone wondering if anyone can offer some advice or give me a hand with a php problem.
What I'd like to do is give my website visitors the option to sort the results of their search queries. For example, let's say you search fir "city" and these results come up:
Miami
New York
Los Angeles
I'd like to give the users a link ("Sort Alphabetically" or something like that) they can click on so that they can sort those results alphabetically. And then click it again and sort in the opposite direction.
Is there any simple way of doing this with PHP (getting results from a MYSQL database).
Thanks for any help!
|
 |
g1smd
Moderator
Joined: Jul 28, 2002
# Posts: 10183
|
Posted: 05/26/2007 10:37 am
There must be many free scripts and code snippets out there can do this. You're unlikely to find anyone that would write one for you for free. A Google search may reap rewards.
|
 |
leelee700
Joined: Oct 09, 2006
# Posts: 50
|
Posted: 05/27/2007 03:21 pm
Thanks g1smd - naturally a Google search (lots and lots of Google searches, actually) was the first thing I did. That didn't turn up anything useful for me. I am here looking for some guidance, like the thousands of other posts on this site.
I understand it conceptually, that I have to take the search results, feed them into an array, and then sort the elements of the results array. Problem is I can't seem to get the creation of the array working right.
So I'm looking for guidance on any and all aspects.
Thanks.
|
 |
Prowler
Moderator
Joined: Aug 14, 2000
# Posts: 1723
|
Posted: 05/27/2007 09:52 pm
You are probably looking to use sort() or asort() functions to sort your contents in an array.
I have an old book - Programming PHP from O'Reilly which gave us some useful insights into the language specific coding for PHP. Most languages have built-in functions to manipulate arrays. Php is no exception. This excerpt from the same book will give you an idea to start you - [link]
|
 |
langardmicro
Joined: Mar 12, 2007
# Posts: 76
|
Posted: 05/28/2007 01:18 am
Don't use PHP to sort. Sort the MySQl query with 'ORDER BY [your_table_variable] DESC ... or ASC as a suffix. You can order by two variables if you wish like:
query...ORDER BY state, city
Change the PHP query variable (like .php?sort=asc or .php?sort=dsc) in your form to fit what query you want to display.
|
 |
david68
Joined: May 16, 2005
# Posts: 144
|
Posted: 05/28/2007 07:13 am
For an example of sorting you could look at PHPBB's forum software (phpbb.com), written in PHP - it's open source and uses sorting for the member's listing and it uses SQL of course. It's pretty simple. Download it, extract it, look at MEMBERLIST.PHP. It's pretty easy really, just a time thing.
|
 |
You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
- You have not yet logged in, or registered properly as a member
- You are a member, but no longer have posting rights.
- This is a private forum, for which you do not have permissions.
If you are a recent member, it's possible that you simply have not yet confirmed your account. Please
check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions
contained within.
If you cannot find this message, click here to Re-Send it.
|
If you are still experiencing problem, please read the
Login Assistance
Article for some advice on what may be causing your login not to work properly.
|
Switch to Advanced Editor and ...
Create a New Topic
or Reply to this Thread
|
|