我有自动完成单个文本字段的PHP代码,有效;但是我试图添加更多字段然后它不起作用。请检查我的代码并帮助我添加更多字段。
这是代码:
autocomplete.php
<?php
// Database Structure
$host="localhost";
$username="root";
$password="";
$databasename="student";
$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);
$searchTerm = $_GET['term'];
$select =mysql_query("SELECT * FROM student_data WHERE fname LIKE '%".$searchTerm."%'");
while ($row=mysql_fetch_array($select))
{
$data[] = $row['fname'];
}
//return json data
echo json_encode($data);
?>
的index.php
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<link rel="stylesheet" href="jquery-ui.css">
<script type="text/javascript">
$(function()
{
$( "#coding_language" ).autocomplete({
source: 'autocomplete.php'
});
});
</script>
</head>
<body>
<div id="wrapper">
<div class="ui-widget">
<p>Enter The First Name</p>
<input type="text" id="coding_language">
</div>
<div class="ui-widget">
<p>Enter The Last Name</p>
<input type="text" id="coding_language">
</div>
</div>
</body>
</html>