Hello,
I’m querying a Mysql database & displaying the results on a html page. This part is working fine.
I now want to sort the query results ascending by clicking on the column headers. I’m using a code which I got from another forum but I don’t know how to edit it. This code is working fine but it re-queries & sorts all the records in the whole database. I don’t want it to re-query & sort all the records in the whole database. I want it to sort only the query results from the 1st query.
Please help me to edit this code. Thank you.
[code=php]<?php
//the 1st query that comes from a html form
$Text_Box_17 = $_POST[‘Text_Box_17’];
$query=”SELECT * FROM land WHERE full_add LIKE ‘%$Text_Box_17%'”;
//the sorting part
$field = $_GET[‘sortby’];
if(isset($field))
{
$query = $query.’ ORDER BY ‘.$field.’ ASC’;
}
//the connection to the mysql database
mysql_connect (“$host”,”$username”,”$password”);
mysql_select_db($database) or die( “Where’s the database man?”);
$result=mysql_query($query);
$num=mysql_numrows($result);
//the table to display the results
?>
<table width=700 border=1 height=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ cellpadding=”0″ cellspacing=”0″>
<tr bgcolor =”cyan”>
<td width=”80″ align=”center” bgcolor=”#CCFFFF”><b><font face=”arial” size=”2.5″><a href=”test_metro_agents.php?sortby=date”>date</a></font></strong></td>
<td width=”570″ align=”center” bgcolor=”#CCFFFF”><b><font face=”arial” size=”2.5″><a href=”test_metro_agents.php?sortby=full_add”>full_add</a></font></strong></td>
<td width=”50″ align=”center” bgcolor=”#CCFFFF”><b><font face=”arial” size=”2.5″><a href=”test_metro_agents.php?sortby=status”>status</a></font></strong></div></td>
</tr>
<tr>
<?php
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td align=”center” bgcolor=”#CCFFFF”><div align=”center”><font face=”arial” size=”2″><?php echo $row[‘date’] ?></font> </div></td>
<td align=”center” bgcolor=”#CCFFFF”><div align=”left”><font face=”arial” size=”2″><?php echo $row[‘full_add’] ?></font> </div></td>
<td align=”center” bgcolor=”#CCFFFF”><div align=”center”><font face=”arial” size=”2″><?php echo $row[‘status’] ?></font> </div></td>
<tr>
<?php
}
?>
</table>