Hi Everyone,
I try to make a resultpage with some column headers like name, email adress, etc. Now I want to make it possible to click on name and that it is possible to sort it that way.
What do I have to change on my code.
<?php
//search.php
require("globals.php");
require("common.php");
//check if at least one search criteria is entered
if (!$cn && !$mail && !$locality && !$description && !$telephonenumber)
{
DisplayErrMsg("Error: At least one search criteria should be present\n");
exit();
}
//generate the sql command for doing a select from the database
$searchStmt = "SELECT * from $tableName where " ;
if ($cn)
$searchStmt .= "name like '%$cn%' and ";
if ($mail)
$searchStmt .= "email like '%$mail%' and ";
if ($locality)
$searchStmt .= "city like '%$locality%' and ";
if ($description)
$searchStmt .= "description like '%$description%' and ";
if ($telephonenumber)
$searchStmt .= "telephone like '$telephonenumber' and ";
$stmt = substr ($searchStmt, 0, strlen ($searchStmt)-4);
//open a persistant connection with database
if (!($link=mysql_pconnect($hostName, $userName, $password)))
{
DisplayErrMsg(sprintf("erro connecting to host %s, by user %s",
$hostName, $userName));
exit();
}
//Select the database $databaseName
if (!mysql_select_db($databaseName, $link))
{
DisplayErrMsg(sprintf("Error in selecting %s database", $databaseName));
DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link)));
exit();
}
//Send the SQL command to the database server for execution
if (!($result = mysql_query ($stmt, $link)))
{
DisplayErrMsg(sprintf("Error in executing %s stmt", $stmt));
DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link)));
exit();
}
//display the results of the query
//and generate table
printf("<TABLE BORDER WIDTH=\"100%%\" BGCOLOR=\"#dcdcdc\" NOSAVE>\n");
printf("<TR>
<TD>Name</TD>
<TD>E-Mail</TD>
<TD>City</TD>
<TD>Description</TD>
<TD>Telephone</TD>
<TD>Modify/Delete</TD>
</TR>\n");
//each result in the result of the SQL query is displayed in a seperate row of the table
while (($row = mysql_fetch_object($result)))
{
//making modify and delete a link
printf("<TR>
<TD>%s</TD>
<TD><A HREF=\"mailto:%s\">%s</a></TD>
<TD>%s</TD>
<TD><A HREF=\"http://%s\">%s</a></TD>
<TD>%s</TD>
<TD><A HREF=\"modify.php?rowid=%s\">Modify</A>/
<A HREF=\"delete.php?rowid=%s\">Delete</A></TD>
</TR>\n",
$row->NAME, $row-> EMAIL,$row->EMAIL, $row->CITY, $row->DESCRIPTION,$row->DESCRIPTION, $row->TELEPHONE,
$row->ROWID, $row->ROWID);
}
printf("</TABLE>\n");
//free the memory associated with $result variable
mysql_free_result($result);
ReturnToMain();
?>