Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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_Ajax - Fatal编程技术网

Php 使用数据库记录自动完成输入

Php 使用数据库记录自动完成输入,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我想将我的PhpMyAdmin记录添加到自动完成函数中,当有人键入名称或其他内容时,它将在数据库中显示要选择的值。必须在“我的输入”字段中的值来自表地址\u状态 我的代码: <?php if(isset($_POST['search'])) { $valueToSearch = $_POST['valueToSearch']; // search in all table columns // using concat mysql function $query = "SELECT per

我想将我的PhpMyAdmin记录添加到自动完成函数中,当有人键入名称或其他内容时,它将在数据库中显示要选择的值。必须在“我的输入”字段中的值来自表地址\u状态

我的代码:

<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT person_id, person_firstname, person_lastname, 
             person_email, person_phonenumber,  
             address_street,address_housenumber, 
             address_city,address_state,address_zipcode,cv_path
      FROM person 
        inner join address on address.address_id = person.person_address 
        inner join cv on cv.cv_id = person.person_cv 
          WHERE CONCAT(`person_firstname`, `person_lastname`, `address_street`, `address_housenumber`, `address_zipcode`, `address_city`, `address_state`, `person_email`, `person_phonenumber` ) 
          LIKE '%".$valueToSearch."%'";

$search_result = filterTable($query);

}
else {
$query = "SELECT person_id, person_firstname, person_lastname, 
             person_email, person_phonenumber,  
             address_street,address_housenumber, 
             address_city,address_state,address_zipcode,cv_path
      FROM person 
        inner join address on address.address_id = person.person_address 
        inner join cv on cv.cv_id = person.person_cv ";
$search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "usbw", "persons");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Detail</title>
    <style>
        table,tr,th,td
        {
            border: 1px solid black;
        }
    </style>
    <script>
function showUser(str) {
if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
} else { 
    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("txtHint").innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
}
}
</script>
</head>
<body>

    <form action="admin2.php" method="post" onchange="showUser(this.value)">
        <input type="text" name="valueToSearch" placeholder="Hoi" style="margin-left: 50px;">
        <input type="submit" name="search" value="Filter"><br><br>
        <div id="txtHint">
        <table>
             <tr>
                <th>Voornaam</th>
                <th>Achternaam</th>
                <th>Straat</th>
                <th>Huisnummer</th>
                <th>Postcode</th>
                <th>Stad</th>
                <th>Provincie</th>
                <th>Email</th>
                <th>Mobiel</th>
                <th>cv</th>
                <th>delete</th>
            </tr>;

  <!-- populate table from mysql database -->
            <?php while($row = mysqli_fetch_array($search_result)):?>
            <tr>
                <td><?php echo $row['person_firstname'];?></td>
                <td><?php echo $row['person_lastname'];?></td>
                <td><?php echo $row['address_street'];?></td>
                <td><?php echo $row['address_housenumber'];?></td>
                <td><?php echo $row['address_zipcode'];?></td>
                <td><?php echo $row['address_city'];?></td>
                <td><?php echo $row['address_state'];?></td>
                <td><?php echo $row['person_email'];?></td>
                <td><?php echo $row['person_phonenumber'];?></td>
                <td><?php echo "<a href='http://localhost:8080/website/" . $row['cv_path'] . "'>cv file</a>";?></td>
                <td><?php echo "<a href='delete.php?person_id=" . $row['person_id'] . "'>delete</a>";?></td>
            </tr>
            <?php endwhile;?>
        </table>
        </div>
    </form>

</body>
</html>

您是否显示了
getuser.php
code?首先,您将不受信任的数据放入SQL查询中,这样在尝试之前我就可以担心您的结构了it@RiggsFolly我将getuser.php添加到同一页面中。当我填写任何信息时,排序是有效的,它只会显示具有该信息的人。但是我只想有一个下拉列表或自动完成,它只显示我可以搜索的信息。。。就像现在我键入示例:Ro时,它将按我的姓名和城市进行检查,因为这也以Ro开头。。。一个包含地址表中的值的下拉列表将是完美的。。。但是自动完成就足够了