Forum Moderators: coopster

Message Too Old, No Replies

Sort By (something)

         

MaticooL

11:35 am on May 23, 2006 (gmt 0)

10+ Year Member



Hi to all!

I am kinda having problem with sort by. I have a database, for example called test and table called test, in the table I have the following rows:

id
fname
lname

I want a drop-down menu on my site with options to Sort by: (in the select menu options)id,fname,lname
Please help!

Thanks in advance!

eelixduppy

11:56 am on May 23, 2006 (gmt 0)



In your drop-down menu, you have to submit whatever they select through a form. Then when you have the value they selected, you can used a query like the following:

$query = "select * from test sort by ".$_POST['sort'];

Habtom

11:57 am on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might need to write a query similar to:

//sorts by fname
SELECT fname, lname FROM test ORDER BY fname

//sorts first by fname then by lname
SELECT fname, lname FROM test ORDER BY fname, lname

I hope this helps, if not please give us a little more detail.

MaticooL

12:21 pm on May 23, 2006 (gmt 0)

10+ Year Member



If you could give me the script, it would be nice. Anyway, here is the form (EXAMPLE!) what is the script and what is the action should be?

<form method="" action="">
<select size="1" name="test">
<option>fname</option>
<option>lname</option>
</select>
</form>

MaticooL

4:09 pm on May 23, 2006 (gmt 0)

10+ Year Member



*BUMP*

coopster

9:08 pm on May 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The action attribute will be the name of the processing script that will accepted the posted data, build an sql query, execute the query and retrieve the result set, process the results and display the html-formatted data. The sql query will have an ORDER BY clause built from the "name" attribute's value much like described earlier.

MaticooL

8:26 pm on May 26, 2006 (gmt 0)

10+ Year Member



Well, and how to do that? Can someone show me the script?

coopster

3:48 pm on May 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you given it your best effort yet? This forum is all about learning and helping each other as opposed to writing the code for you [webmasterworld.com]. Please give it your best shot, if you get stuck, ask specific questions and we will be more than happy to help you accomplish your goal, all the while learning PHP along the way.