Re: Display criteria
| From: | Richard Lynch | Date: | Thu, 11 Jul 2002 09:44:37 +0000 |
| Subject: | Re: Display criteria | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-107082@lists.php.net to get a copy of this message | ||
>I want to display data based on the criteria selected by the user eg click
>on size to display smallest to largest, or by price smallest to highest,
>location etc etc
>
>what is the code I need?
Assuming PHP/MySQL, you'd want something not unlike:
<?php
if (!isset($order)){
$order = 'title';
$ascdesc = 'asc';
}
$query = "select title, size, price from products ";
$query .= " order by $order $ascdesc ";
$products = mysql_query($query, $connection) or error_log(mysql_error());
echo "<TABLE>\n";
echo " <TR>\n";
echo " <TH><A HREF=$PHP_SELF?order=title&ascdesc=asc>^</A><A
HREF=$PHP_SELF?order=title&ascdesc=desc>v</A></TH>\n";
echo " <TH><A HREF=$PHP_SELF?order=size&ascdesc=asc>^</A><A
HREF=$PHP_SELF?order=size&ascdesc=desc>v</A></TH>\n";
echo " <TH><A HREF=$PHP_SELF?order=price&ascdesc=asc>^</A><A
HREF=$PHP_SELF?order=price&ascdesc=desc>v</A></TH>\n";
echo " </TR>\n";
while (list($title, $size, $price) = mysql_fetch_row($products)){
echo "
<TR><TD>$title</TD><TD>$size</TD><TD>$price</TD></TR>\n";
}
echo "</TABLE>\n";
?>
Disclaimer: I'll be damned if I can ever tell if ^ is suppose to represent
ASC or DESC in these stupid interfaces. I just click until I get what I
want. YMMV.
--
Like Music? http://l-i-e.com/artists.htm
Off-Topic: What is the moral equivalent of 'cat' in Windows?