Jump to content

Archived

This topic is now archived and is closed to further replies.

natrone

noob in need of some help

Recommended Posts

Hello, I\'m a noob in need of some help. I currently have a page displaying all contents of a mysql table. There are 5 fields in the table. Name, Games Played, Points, Interceptions and Sacks. Works great.

 

I want to create a drop down menu with options- name, points, interceptions and sacks. And when the option is selected from the menu, then the data is listed by that option is descending order. I\'m assuming I use the get function but not sure.

 

Currently the table displays by name in descending order, but I want for example, if you select points from the menu, that the table is requeried to list the data by points in descending order and so on. Hope this makes sense. Any advise is appreciated. Please make it easy to understand. Thanks in advance.

Share this post


Link to post
Share on other sites

Add a form with the dropdown in it.

 

<form name="form1" method="get" action="<?=$_SERVER[PHP_SELF]?>" >

<SELECT name="orderby">

<OPTION Value="Name">Name</OPTION>

<OPTION Value="Games Played">Games Played</OPTION>

<OPTION Value="Points">Points</OPTION>

<OPTION Value="Interceptions ">Interceptions </OPTION>

<OPTION Value="Sacks">Sacks</OPTION>

</SELECT>

<INPUT type="submit" value="Sort">

</form>

Get the selected value, defaulting to name if no selection

 

[php:1:2ea7f60812]<?php

$orderby = isset($_GET[\'orderby\']) ? $_GET[\'orderby\'] : \'Name\' ;

?>[/php:1:2ea7f60812]

Set up your query

[php:1:2ea7f60812]<?php

$query = \"SELECT Name, `Games Played`, Points, Interceptions , Sacks

FROM tablename ORDER BY `$orderby` DESC \";

?>[/php:1:2ea7f60812]

Process results as now.

 

hth

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.