我有一个 ajax 实时搜索脚本,但它似乎只返回数组的第一行。不知道这是否与我的循环有关,但是,如果有人能发现错误,将非常感谢帮助,因为我似乎找不到它。我不包括 javascript,因为我很确定这不是错误,因为 php 文件正在触发。它只是回响第一个点击,而不是迭代其他点击。
//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;
最佳答案
您将在每次 while
循环迭代中覆盖您的 $hint
变量。尝试在 while
之前声明它(删除现在拥有它的位置)
$hint = "";
while($a = mysql_fetch_array($res,MYSQL_BOTH))
{
关于php mysql ajax 实时搜索数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10933266/