View Single Post
Old Apr 27th, 2006, 7:38 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
As a matter of fact, I whipped this up, and it works. I stayed as close to your code as possible, so fair warning, its ugly. See it here.
EDIT: Oh, you do realize you have "DESC" in there, right?
<?php
if ($_POST ['view']) $view = $_POST ['view']; else $view = 'fullname';
require_once ("functions.php");
demoConnect ();

$query = "SELECT * FROM Demonstration  ORDER BY $view DESC";
$result = mysql_query ($query) or die (mysql_error () . "query op<br/>"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sort Test</title>
</head>
<body>
<?php
echo '<TABLE border="1">'; 
echo '<TR><TD><B>Full Name</B></td><TD><B>Email Address</B></td><TD><B>Date and time</B></td><TD><B>Message</td></B></TR>';
while($myrow = mysql_fetch_array($result)) 
{ 
echo '<TR><TD>'; 
echo $myrow['fullname']; 
echo "<TD>"; 
echo $myrow['emailaddress'];  
echo "<TD>"; 
echo $myrow['date']; 
echo "<TD>"; 
echo $myrow['message']; 
} 
echo '</TABLE>';
?>
<form action="sort.php" name="form" method="post">
<select name="view">
<option value="fullname">fullname a-z
<option value="emailaddress"> email a-z
</select>
<input type="submit" name="submit">
</form>
</body>
</html>
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote