Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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的网页中使用自动完成?_Php_Jquery_Mysql_Jquery Ui_Autocomplete - Fatal编程技术网

如何在php的网页中使用自动完成?

如何在php的网页中使用自动完成?,php,jquery,mysql,jquery-ui,autocomplete,Php,Jquery,Mysql,Jquery Ui,Autocomplete,我分别用php和MySQL创建了一个带有简单搜索引擎的简单网页 以下是index.php: <form action="search.php" method="get" > Please search here: <input type="text" name="query" id="text" /> <input type="submit" name="submit" id="search" value="Search" /> </form

我分别用php和MySQL创建了一个带有简单搜索引擎的简单网页

以下是index.php:

<form action="search.php" method="get" >
Please search here:
    <input type="text" name="query" id="text"  />
 <input type="submit" name="submit" id="search" value="Search" />
</form>

请在此搜索:
search.php:

<?php
    mysql_connect("", "", "") or die("Error connecting to database: ".mysql_error());
    mysql_select_db("search-engine") or die(mysql_error());
    $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends

$qstring = "SELECT description as value,id FROM test WHERE description LIKE '%".$term."%'";
$result = mysql_query($qstring);//query the database for entries containing the term

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
        $row['value']=htmlentities(stripslashes($row['value']));
        $row['id']=(int)$row['id'];
        $row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
    $query = $_GET['query'];
    $min_length = 3;
  if(strlen($query) >= $min_length)
  {
        $query = htmlspecialchars($query);
        $query = mysql_real_escape_string($query);
  echo "<table border='0' width='300' align='center' cellpadding='1' cellspacing='1'>";
  echo "<tr><h3>You have searched for $query...Please find the details of $query...</h3></tr>";
  echo "<tr align='center' bgcolor='#03acfa' > <td height='35px' width='150px'><b>Mobile Name</b></td> <td><b>Mobile Type</b></td></tr>";
        $result = mysql_query("SELECT * FROM mobiles WHERE (`name` LIKE '%".$query."%') OR (`type` LIKE '%".$query."%')") or die(mysql_error());
        if(mysql_num_rows($result) > 0)
  {
            while($results = mysql_fetch_array($result))
   {
                echo "<tr align='center' bgcolor='#93dafb'><td height='25px'>".$results['name']."</td> <td>".$results['type']."</td></tr>" ;
            }

        }
        else{
            echo "<tr align='center' bgcolor='#fdee03'><td colspan='2' height='25px'>Sorry..No results for $query</td><tr>";
   echo "</table>";
        }
    }
    else{
        echo "Your search keyword contains letters only ".$min_length;
    }
?>

你有没有尝试过任何方法来实现这一点?无意冒犯,但如果你只是谷歌,比如jqueryautocomplete,你会发现一些清晰的文档,说明你如何集成itI,我正在努力使用它@LeventeNagy谢谢你被卡住了吗。。?这里您需要什么帮助:您可以创建一个外部php文件并使用它。从那里返回json结果
<div>
<p>Saina Nehwal poses with the World Junior Badminton Championship trophy at the Shiv Chattrapati Sports Complex in this November 2, 2008.</p>
</div>