I’ve done my best not to bother you folks with this but am stumped. I’ve found some tutorials for searching a database and have managed to get a search happening. However, the list of names found (I searched on “Smith” because I knew there was more than one) just repeats the FIRST name in the db, instead of the supposedly found names (Ian Smith, Robert Smith, etc.). I’ve read and read and read the code but can’t find the problem. This is the code I’m using and I would love it if someone could please tell me what I’ve done wrong - thanks!:
<?php require_once(‘Connections/db9568.php’); ?>
<?php
if (!function_exists(“GetSQLValueString”)) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = “”, $theNotDefinedValue = “”)
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists(“mysql_real_escape_string”) ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case “text”:
$theValue = ($theValue != “”) ? “'” . $theValue . “'” : “NULL”;
break;
case “long”:
case “int”:
$theValue = ($theValue != “”) ? intval($theValue) : “NULL”;
break;
case “double”:
$theValue = ($theValue != “”) ? doubleval($theValue) : “NULL”;
break;
case “date”:
$theValue = ($theValue != “”) ? “'” . $theValue . “'” : “NULL”;
break;
case “defined”:
$theValue = ($theValue != “”) ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_db9568, $db9568);
$query_rsJudgesSearch = “SELECT judgeID, firstName, lastName, city, province, country, emailaddy, ckcNumber, akcNumber, cdjaNumber, otherNumber, breedsOwned, kennelName, description
, breedsJudged FROM judgegallery”;
$rsJudgesSearch = mysql_query($query_rsJudgesSearch, $db9568) or die(mysql_error());
$row_rsJudgesSearch = mysql_fetch_assoc($rsJudgesSearch);
$totalRows_rsJudgesSearch = mysql_num_rows($rsJudgesSearch);
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
<title>Search Contacts</title>
</head>
<p><body>
<h3>Search Contacts Details</h3>
<p>You may search either by first or last name</p>
<form method=“post” action=“judgestest-search.php?go” id=“searchform”>
<input type=“text” name=“name”>
<input type=“submit” name=“submit” value=“Search”>
</form>
<?php
if(isset($_POST[‘submit’])){
if(isset($_GET[‘go’])){
if(preg_match(“/[A-Z | a-z]+/”, $_POST[‘name’])){
$name=$_POST[‘name’];
//-query the database table
$sql=“SELECT judgeID, firstName, lastName FROM judgegallery WHERE firstName LIKE '%” . $name . “%’ OR lastName LIKE '%” . $name .“%'”;
//-run the query against the mysql query function
$result=mysql_query($sql);
//-count results
$numrows=mysql_num_rows($result);
echo “<p>” .$numrows . " results found for " . stripslashes($name) . “</p>”;
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row_rsJudgesSearch['firstName'];
$LastName=$row_rsJudgesSearch['lastName'];
$ID=$row_rsJudgesSearch['judgeID'];
//-display the result of the array
echo "<ul>
";
echo “<li>” . “<a href=\“judgestest-search.php?id=$ID\”>” .$FirstName . " " . $LastName . "</a></li>
";
echo “</ul>”;
}
}
else{
echo “<p>Please enter a search query</p>”;
}
}
}
?>
</body>
</html>
<?php
mysql_free_result($rsJudgesSearch);
?>
</p>