首页 > 解决方案 > 过滤Mysql中的数据

问题描述

我试图“过滤”这些数据,以便 [bøde]... 唯一得到回显。而不是所有其他数据。

我要过滤的数据 我要过滤的数据

我怎样才能做到这一点?我完全不知道。

我试图[bøde]在此表中回显:

在此表中:

“测试”在哪里。

vrp_user_data就是问题所在,我不知道如何过滤它,所以它不会回显所有的 dvalue 数据

<?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>

我的英语不太好,所以如果您想了解更多信息,请随时帮助我:)

标签: phpmysqldatabasehtml-tablefiltering

解决方案


我不太明白你的意思,但如果我错了,我会纠正我你是否正在尝试构建搜索查询?

如果是这样,您无法像在那里那样从 2 个表中搜索,则必须使用内部联接进行 2 个查询:

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

现在添加您其余的参数,希望它对您有所帮助,否则请让我知道我不是您要找的这个。


推荐阅读