【问题标题】:Filter data in Mysql过滤Mysql中的数据
【发布时间】:2018-12-04 10:36:09
【问题描述】:

我试图“过滤”这些数据,所以[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>

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

【问题讨论】:

    标签: php mysql database html-table filtering


    【解决方案1】:

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

    如果这样你不能像你在那里那样从 2 个表中搜索,你必须使用内部连接来进行 2 个查询:

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

    现在添加其余参数,希望对您有所帮助,否则请告诉我我不是您要找的那个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 2020-02-22
      • 2022-07-30
      • 2013-08-09
      • 2015-05-26
      • 2018-03-21
      • 2023-03-11
      相关资源
      最近更新 更多