I have a query that pulls info from a database. One of my variables, we will call it $title - has the following content options (CEO, CFO, Administrator, Manager, Worker).
The correct ORDER for this information is CEO, CFO, Manager, Administrator, Worker...but alphabetically that is not the case. How do I assign some sort of forced "order" so that when a viewer clicks on my column header, it orders correctly? Here is my code:
<?php
if ($order == 1) {
$order = "TBL_name";
}
// ---------------- HERE IS MY PROBLEM --------------- //
elseif ($order == 2) {
$order = "???, TBL_name";
}
// ---------------- HERE IS MY PROBLEM --------------- //
elseif ($order == 3) {
$order = "TBL_hiredate, TBL_name";
}
else {$order = "TBL_hiredate, TBL_name";
}
$result = mysql_query("SELECT * FROM TBL_Emp WHERE TBL_current='Yes' GROUP BY TBL_name ORDER BY $order");
$number = MYSQL_NUMROWS($result);
$i = 0;
IF ($number == 0) :
PRINT "<CENTER><P>There is nobody that matched your search!</CENTER>";
ELSEIF ($number > 0) :
PRINT "<P>";
ENDIF;
if ($myrow = mysql_fetch_array($result)) {
echo "<table align=center border=0 cellpadding=2><tr><td colspan=4><center>There are $number employees.</center></td></tr>
<tr class=content-title>
<td><A HREF=$PHP_SELF?order=1>Name</A></td>
<td>Email</td>
<td><A HREF=$PHP_SELF?order=2>Title</A></td>
<td><A HREF=$PHP_SELF?order=3>Hired</A></td></tr>\n";
do {
$time = date("m/d/Y", $myrow["TBL_hiredate"]);
printf("<tr class=content-text>
<td nowrap><B>%s</B></td>
<td nowrap><a href=mailto:%s>%s</a></td>
<td nowrap>%s - %s</td>
<td nowrap>%s</td></tr>\n",
$myrow["TBL_name"],
$myrow["TBL_email"],
$myrow["TBL_title"],
$time);
}
while ($myrow = mysql_fetch_array($result));
}
else { echo "No active employees?";
}
?>