I want PHP to keep the user on the same search page (or bring them back to the search page) if there are no rows to display from the user's search. My search page lets the user search by employee name, but I can't figure out how to check to see if there are rows to display first.
I tried using the snippit below (Kirk, if you're reading this, this is what you recommended earlier)
" if ($numrow < 1)
echo "No records found";
else
{
// go ahead and display them... "
But where do I put this? and how do I redirect the user back to the original search page and display a "no records found" message so that the user can try again? *
I've pasted most of the code below from the results page that I'm using.
If anyone can tell me exactly what to put and where to put it, it would be greatly appreciated.
-Thanks.
<?
$dbh=mysql_connect("localhost","username","password");
mysql_select_db("databasename",$dbh);
if(empty($offset))
$offset=0;
$query="
select distinct
employees.employeeID as employeeID,
employees.name as name,
employees.scheduleID as scheduleID,
schedule.schedule_details as schedule_details
from
employees,
schedule
where (
employees.scheduleID=schedule.scheduleID and
employee.name like '%$name%'
)
order by name
limit $offset,20
";
$result = mysql_query($query,$dbh);
$numrow = mysql_numrows($result);
?>
<BODY>
* graphics, header, table go here
<?
$counter=0;
$linenumber=1;
do {
\for alternating row colors\
if (is_int($counter/2)):
$bgcolor="#eeeeee";
else:
$bgcolor="#ffffff";
endif;
$employeeID=mysql_result($result,$counter,"employeeID");
$name=mysql_result($result,$counter,"name");
$scheduleID=mysql_result($result,$counter,"scheduleID");
$schedule_details=mysql_result($result,$counter,"schedule_details");
?>
start displaying results here
<? echo $name ?> <BR>
<? echo $schedule_details ?>
</BODY>