I was told that I could change the direction of the sort order of a collum by adding a second variable to the URLs in the Table headers below... However, I really can't think of how to do this.... Ie. You click on a link and the table sorts for that column in a descending order. You click on it a second time and it sorts in an assending order...
<?php
$validColumns = array('Menu_item','Menu_desc','Menu_price','Menu_pict','Menu_cat');
if (isset($_GET['orderby']) && in_array($_GET['orderby'],$validColumns))
{
$order = $_GET['orderby'];
}
else
{
$order = 'Menu_id';
}
$SQL="SELECT * FROM Main_Menu ORDER BY $order DESC";
$result=mysql_query($SQL,$dB);
$num = mysql_num_rows($result);
$cur = 1;
echo '<table width="600" border="0" cellspacing="2" cellpadding="2" class="content">
<tr>
<td align="right">';
echo "Total number of items: $num";
echo '</td></tr></Table>';
echo '<table width="600" border="0" cellspacing="2" cellpadding="2" class="content">
<tr BGCOLOR="777777">
<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?orderby=Menu_item"><b>Item</b></a></td>
<td Width="300"><b>Description</b></td>
<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?orderby=Menu_price"><b>Price</b></a></td>
<td nowrap><b>Pict</b></td>
<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?orderby=Menu_cat"><b>Cat</b></a></td>
<td nowrap><b>action</b></td>
</tr>';
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$Menu_id = $row["Menu_id"];
$Menu_item = $row["Menu_item"];
$Menu_desc = $row["Menu_desc"];
$Menu_price = $row["Menu_price"];
$Menu_pict = $row["Menu_pict"];
$Menu_cat = $row["Menu_cat"];
echo "<tr><td nowrap><B>$Menu_item</B></td><td>$Menu_desc</td><td>\$$Menu_price</td><td>$Menu_pict</td><td>$Menu_cat</td><td nowrap><a href=\"$PHP_SELF?t=2&Menu_id=$Menu_id\">edit</a> | <a href=\"$PHP_SELF?t=4&Menu_id=$Menu_id\">delete</a></td></tr>";
$cur++;
}
echo "</table>";
?>