Sorting MYSQL entries
Posted: Mon Jun 23, 2003 9:37 am
I am wrinting a script to sort mysql entries. I have the correct table displayed but it seems its running my If statements without checking the variable. Im trying to get the table to be sorted based on user input
Heres the code
Heres the code
Code: Select all
<? include ("./config.php") ?>
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form name="form1" method="POST" action="">
<input name="test" type="text" id="sort" name="sort">
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
<table border="0" width="100%" cellspacing="1" cell padding="0" bordercolor="#000000" bgcolor="FFFFFF">
<tr>
<td width="5px" bgcolor="90A0C1"><p align="center"><small><font face="Verdana">id</font></small></td>
<td width="75px" bgcolor="90A0C1"><p align="center"><small><font face="Verdana">Job Title</font></small></td>
<td width="235px" bgcolor="90A0C1"><p align="center"><small><font face="Verdana">Details</font><center></small></td>
<td width="75px" bgcolor="90A0C1"><p align="center"><small><font face="Verdana">Location</font><center></small>
<td width="85px" bgcolor="90A0C1"><p align="center"><small><font face="Verdana">Date Posted<center></font></small>
</td>
<?
if($sort == title); {
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY designation";
}
if($sort == city);
{
$query = "SELECT jcode, designation, responsibilities, city, posted FROM listing ORDER BY city";
}
$result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error());
if(mysql_num_rows($result)) {
$rank = 1;
while($row = mysql_fetch_row($result))
{
print("</tr><tr>");
if($color == "#FFFFFF") {
$color = "#DFDFDF";
} else {
$color = "#FFFFFF";
}
print("<td width="5px" bgcolor="$color"><center><small>");
print("<font face="Verdana">$rank</font></small></center></td>");
print("<td width="75px" bgcolor="$color"><left><small>");
print("<font face="Verdana">$row[1]</font></small></center></td>");
print("<td width="235px" bgcolor="$color"><small>");
print("<font face="Verdana">$row[2]</font></small></center></td>");
print("<td width="75px" bgcolor="$color"><left><small>");
print("<font face="Verdana">$row[3]</font></small></left></td>");
print("<td width="85px" bgcolor="$color"><left><small>");
print("<font face="Verdana">$row[4]</font></small></left></td>");
$rank++;
}
}
?>