Jump to content

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.

Link to comment
https://forums.phpfreaks.com/topic/1562-noob-in-need-of-some-help/
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.