I have an ajax live search script working except that it only seems to be returning the first row of the array. Don’t know if it is something with my loop, however, if anyone can spot error, would greatly appreciate help as I cannot seem to find it. I am not including javascript cause I’m pretty sure that is not error as php file is firing. It is just echoing the first hit and not iterating through others.
//run query on dbase then use mysql_fetch_array to place in array form
while($a = mysql_fetch_array($res,MYSQL_BOTH))
{
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
$n = $a['first']." ".$a['last'];
if ($hint=="")
{
$hint='<a href="mailto.php">'.$n.'</a>';
}
else
{
$hint=$hint.'<br><a href="mailto.php">'.$n.'</a>';// we do not seem to get here
}
}
}
}
// Set output to "no suggestion" if no hints were found
// or to the correct values
}//close while fetch
echo $hint;
You’re overwriting your
$hintvariable on everywhileloop iteration. Try declaring it before thewhile(remove where you have it now)