在mysql中过滤数据

wfsdck30  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(446)

我试图“过滤”这些数据,以便 [bøde]... 只会发出回声。而不是所有其他的数据。
我要过滤的数据

我该怎么做?我完全不知道。
我试着回应 [bøde] 在此表中:

“测试”在哪里。
是的 vrp_user_data 这就是问题所在,我不知道如何过滤它,所以它不会回显所有的数据值

<?php

if(isset($_POST['search']))
{

    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `vrp_user_identities`, `vrp_user_data` WHERE CONCAT(`user_id`, `firstname`, `name`, `age`, `phone`, `registration` ) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($query);

}
 else {
    $query = "SELECT * FROM `vrp_user_identities`, `vrp_user_data` ";
    $search_result = filterTable($query);
}

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

?>

<!DOCTYPE html>
<html>
    <head>
        <title>FOLKEREGISTER</title>

    </head>
    <body><center>
        <center><h1>søg i det centrale personregister "CPR"</h1></center>
        <form action="https://mesogames.dk/DDC/FOLKEREGISTER.php" method="post">
            <input type="text" name="valueToSearch" placeholder="SØG I CPR"><br><br>
            <input type="submit" name="search" value="søg/genlæs"><br><br>

            <table>
                <tr>

                    <th>Fornavn</th>
                    <th>Efternavn</th>
                    <th>Alder</th>
                    <th>CPR</th>
                    <th>Telefon nummer</th>
                    <th>Test</th>
                </tr>

      <!-- populate table from mysql database -->
                <?php while($row = mysqli_fetch_array($search_result)):?>
                <tr>

                    <td><?php echo $row['firstname'];?></td>
                    <td><?php echo $row['name'];?></td>
                    <td><?php echo $row['age'];?></td>
                    <td><?php echo $row['registration'];?></td>
                    <td><?php echo $row['phone'];?></td>
                    <td><?php echo $row['dvalue'];?></td>
                </tr>
                <?php endwhile;?>
            </table>
        </form>

    </body></center>    
</html>

我不太擅长英语,所以如果你想了解更多信息,请尽管问:)

dphi5xsq

dphi5xsq1#

我不太明白你的意思,但从我得到的更正我,如果我错了你是想建立一个搜索查询?
如果这样,您就不能像现在这样从2个表中进行搜索,那么您必须使用inner join for 2查询:

$query = "SELECT column-names FROM table-name1 JOIN table-name2 ";

现在加上你其余的参数,希望它能帮助你否则让我知道我不是这个你要找的。

相关问题