redisplay search criteria
Posted: Thu Dec 02, 2010 3:34 pm
I have a page that displays data from the database. The user has option of entering some search criteria and reset the page. This works, but I'm losing the search criteria after the data is displayed. Here is a portion of my code with the two forms.
So if a user chooses "Job Number" for the search criteria field and enter the job number I want the data to display AND keep the criteria.
Thanks for any assistance with this matter.
Code: Select all
<form name="search" method="post" action="<?=$PHP_SELF?>">
<b>Seach for:</b> <input type="text" name="find" /> <b>in</b>
<Select NAME="field">
<Option VALUE="job_nm">Job Name</option>
<Option VALUE="job_num">Job Number</option>
<Option VALUE="insp_nm">Inspector</option>
<Option VALUE="wo_num">Work Order</option>
<Option VALUE="wo_status">WO Status</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" /> </form>
<p>Work status is Active, Scheduled, Complete, or Cancelled</p>
<?php
include ("dbconnect.inc.php");
if ($searching =="yes" and !$find == "") {
//Now we search for our search term, in the field the user specified
$query = mysql_query("Select * from work_orders,customer, jobs, inspector where wo_insp_id = insp_id and wo_cust_id = cust_id and wo_job_id = job_id and upper($field) LIKE '%$find%' order by wo_num");
}
else
{
$query = mysql_query("Select * from work_orders,customer, jobs, inspector where wo_insp_id = insp_id and wo_cust_id = cust_id and wo_job_id = job_id order by wo_num");
}
echo "<table border='1' style='border-collapse' width='95%' cellpadding='2'>
<td><b>WO Num<b></td>
<td><b>Customer<b></td>
<td><b>Job Name</b><b></td>
<td><b>Job Num<b></td>
<td><b>Inspector<b></td>
<td><b>WO Status<b></td>
<td><b>Edit<b></td>
<td><b>Delete<b></td>";
while($row = mysql_fetch_array($query))
{
$inm = $row['insp_nm'];
$wonum = $row['wo_num'];
$custnm = $row['cust_nm'];
$jobnm = $row['job_nm'];
$jobnum = $row['job_num'];
$wostat = $row['wo_status'];
$woid = $row['wo_id'];
//display results in a table
echo "<form name='results' method='post' action=' '>
<tr><td>$wonum</td>
<td>$custnm</td>
<td>$jobnm</td>
<td>$jobnum</td>
<td>$inm</td>
<td>$wostat</td>
<td><a href='workorder_upd.php?wo_id=$woid'>Edit</a></td>
<td><a href='workorder_del.php?wo_id=$woid'>Delete</a></td>
</tr>";
}
echo "</table></form><br></br>";
$count = mysql_num_rows($query);
if ($count == 0)
{
echo "Sorry, but we can not find an entry to match your query<br>"; exit;
}
echo "<b>Search Criteria: </b> " .$find;
mysql_close();
?>
Thanks for any assistance with this matter.