I have written/modified a script that searches a table for a name that user wants to look for. it works. the problem I am having is if there are multiple names that are the same it will only return the first one it finds. what do I need to do to have the script keep searching? here is what I have so far:
<?php
require('mydb.inc');
mysql_connect("localhost",$user,$password);
$database="employeeprofiles";
@mysql_select_db("$database") or die( "Unable to select database");
/*Search database for name*/
$query="SELECT name,position,extention,phone from employees where name like '%$searchtext%'";
$result=mysql_query($query);
mysql_close();
/*Display Results*/
$num=mysql_numrows($result);
if ($num == 0) {
echo "I'm sorry. There were no matches for that name.";
}
else {
$name = mysql_result($result,0,"name");
$position=mysql_result($result,0,"position");
$ext=mysql_result($result,0,"extention");
$phone=mysql_result($result,0,"phone");
echo "<tr bgcolor=\"c2ccff\"><td align=middle><b>$name</b></td><td align=middle><b>$position</b></td>";
echo "<td align=middle><b>$ext</b></td><td align=middle><b>$phone</b>";
echo "</td></tr></table>";
}
?>
------------------
bl@cky
<?php
require('mydb.inc');
mysql_connect("localhost",$user,$password);
$database="employeeprofiles";
@mysql_select_db("$database") or die( "Unable to select database");
/*Search database for name*/
$query="SELECT name,position,extention,phone from employees where name like '%$searchtext%'";
$result=mysql_query($query);
mysql_close();
/*Display Results*/
$num=mysql_numrows($result);
if ($num == 0) {
echo "I'm sorry. There were no matches for that name.";
}
else {
$name = mysql_result($result,0,"name");
$position=mysql_result($result,0,"position");
$ext=mysql_result($result,0,"extention");
$phone=mysql_result($result,0,"phone");
echo "<tr bgcolor=\"c2ccff\"><td align=middle><b>$name</b></td><td align=middle><b>$position</b></td>";
echo "<td align=middle><b>$ext</b></td><td align=middle><b>$phone</b>";
echo "</td></tr></table>";
}
?>
------------------
bl@cky