Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何启用使用php ajax mysql选择实时搜索结果?_Php_Mysql_Ajax_Livesearch - Fatal编程技术网

如何启用使用php ajax mysql选择实时搜索结果?

如何启用使用php ajax mysql选择实时搜索结果?,php,mysql,ajax,livesearch,Php,Mysql,Ajax,Livesearch,我一直在尝试使用php ajax mysql实现实时搜索。我能够在关键笔划上提取结果,但我不知道如何启用选择任何结果 有人能帮我知道怎么做吗 以下是ref的代码: HTML: PHP: for($i=0;$iprepare($query)){ $param=“%”,$userInput[$i]。“%”; $ids=array(); $stmt->bind_param('sss',$param,$param,$param,$param); $stmt->execute(); $stmt->bind

我一直在尝试使用php ajax mysql实现实时搜索。我能够在关键笔划上提取结果,但我不知道如何启用选择任何结果

有人能帮我知道怎么做吗

以下是ref的代码: HTML:

PHP:

for($i=0;$iprepare($query)){
$param=“%”,$userInput[$i]。“%”;
$ids=array();
$stmt->bind_param('sss',$param,$param,$param,$param);
$stmt->execute();
$stmt->bind_result($id、$name、$company、$title、$bio、$website、$imgURL);
如果($stmt->fetch()){
如果(!数组_搜索($id,$id))
{
$id[$i]=$id;
$findResult=true;
//如果有结果,则显示结果
回声'
';
}
}
其他的
{
$stmt->close();
}
}
}


谢谢。

“但我不知道如何启用选择任何结果”。请澄清。最好用一个简单的jsfiddle呈现它,就像谷歌搜索结果一样,我们选择其中一个建议。当我们选择时,结果将添加到搜索栏,对吗?我想做同样的事情。sry,没有在^^上阅读,那么问题是什么,你的休息时间在哪里?嘿,我想启用选择任何搜索结果,以便将其复制到搜索栏。我不能用上面的代码来做这件事,所以我想知道是否还有其他东西需要添加到它中。
 <div class="searchBar" >
 <input type="text" id="searchResidents" name="searchResidents" placeholder="Enter a keyword here..." onkeyup=" showResult(this.value)">
 <input type="submit" id="searchSubmit" name="searchSubmit" value="search">
 </div>
 function showResult(str){
 onsole.log("Livesearch js is invoked");
 if (str.length==0)
 { 
   document.getElementById("livesearch").innerHTML="";
   document.getElementById("livesearch").style.border="0px";
   return;
 }
 if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
       }
  else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
      xmlhttp.onreadystatechange=function()
     {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
        document.getElementById("livesearch").style.border="1px solid #A5ACB2";
      }
     }
     xmlhttp.open("GET","livesearch.php?q="+str,true);
      xmlhttp.send();
    }
            for($i=0;$i<$arraySize;$i++)
    {
        if($stmt = $mysqli->prepare($query)){
        $param="%".$userInput[$i]."%";
        $ids=array();
        $stmt->bind_param('sss', $param,$param,$param);
        $stmt->execute();
        $stmt->bind_result($id, $name,$company, $title, $bio, $website, $imgURL);
        if($stmt->fetch()){
        if(!array_search($id,$ids))
        {
        $ids[$i]=$id; 
            $findResult=true;
            //If there is a result, display the results
            echo '<span class="peoplesection">
            <a href="javascript:void(0);" class="viewOverlay"         rel='.$id.'>
            <img src='.$imgURL.' alt="Photo of: "'.$name.'>
            <h1 class="peopleh1">'.$name.'</h1>
            <h2 class="peopleh2">'.$company.'</h2>
            <h3 class="peopleh3">'.$title.'</h3>
            </a>
            </span>';
            }
            }
            else
            {
        $stmt->close();
        }

        }
    }