我有一个ajax实时搜索脚本,除了它似乎只返回数组的第一行。不知道这是否与我的循环,但是,如果任何人都可以发现错误,将不胜感激帮助,因为我似乎无法找到它。我不包括JavaScript因为我很确定这不是错误,因为PHP文件正在解雇。这只是回应第一次打击而不是重复其他人。php mysql ajax实时搜索阵列
//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;
将在循环的每次迭代中被覆盖?尝试使用'。='来代替,这会将值连接在一起。 – martincarlin87