Jump to content


Photo

noob in need of some help


  • Please log in to reply
1 reply to this topic

#1 natrone

natrone
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 27 December 2003 - 10:32 PM

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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 December 2003 - 08:44 AM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users