mysqli php过滤器已经过滤了表

时间:2017-08-08 16:37:13

标签: php mysqli

嘿伙计们我制作了一张桌子,只向用户显示他们“被标记为”的内容,并且只显示某些“ID”(测试功能性想法)

如何为这个已经过滤的数据创建一个搜索栏,只会从已经显示的内容中返回过滤后的数据?

<?php

$connect = mysqli_connect("localhost", "root", "", "testdb");
$query = "SELECT * FROM `info` WHERE CONCAT(`name`) LIKE '%".$_SESSION['sess_user']."%' OR (`id`) LIKE '29'";
$result1 = mysqli_query($connect, $query);

while($row = mysqli_fetch_array($result1, MYSQLI_ASSOC)):?>

<table class="fixed" border="1" cellpadding="1" cellspacing="1">
  <col width="200px" />
  <col width="300px" />
  <col width="300px" />
  <col width="300px" /><tr>
    <td><?php echo $row['id'];?></td>
    <td><?php echo $row['name'];?></td>
    <td><?php echo $row['surname'];?></td>
    <td><?php echo $row['age'];?></td>
</tr>

<?php endwhile;

当前的搜索功能。 (目前搜索完整的数据库)

<?php

if(isset($_POST['search']))
  {
       $valueToSearch = $_POST['valueToSearch'];
      // search in all table column
      // using concat mysql function
      $query = "SELECT * FROM `info` WHERE CONCAT(`id`, `name`, `surname`, `age`) LIKE '%"."$valueToSearch"."%'";
      $search_result = filterTable1($query);
          }else {

            $query = "SELECT * FROM `info`";
            $search_result = filterTable1($query);
            }


// function to connect and execute the query
function filterTable1($query)
{
$connect = mysqli_connect("localhost", "root", "", "testdb");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>

0 个答案:

没有答案