Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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
如何使用mysql+php在数据库生成的列表中进行搜索_Php_Mysql - Fatal编程技术网

如何使用mysql+php在数据库生成的列表中进行搜索

如何使用mysql+php在数据库生成的列表中进行搜索,php,mysql,Php,Mysql,我使用了下面的php+mysql代码生成了一个复选框列表,其中包含员工姓名和员工ID作为该复选框的值 <?php while($row = mysqli_fetch_array($run_qry)) { echo "<input type='checkbox' name='emply[]' value='91".$row['empid']."'>".$row['fname']." ".$row['lname']; echo "<br>"; } ?> 有了这

我使用了下面的php+mysql代码生成了一个复选框列表,其中包含员工姓名和员工ID作为该复选框的值

<?php
while($row = mysqli_fetch_array($run_qry))
{
echo "<input type='checkbox' name='emply[]' 
value='91".$row['empid']."'>".$row['fname']." ".$row['lname'];
echo "<br>";
}
?>
有了这个代码段,我得到了员工列表,现在我想在这个列表上面有一个搜索框,用于搜索生成的列表,这样我就可以轻松地选择特定的员工。 帮我解决这个问题。
提前感谢。

要在客户端解决这个问题,您需要一个JS解决方案

只需将数组示例替换为BD的结果集

<script>
  // the function searches in elements with class 'class_searh' the string 'string_searh'
  function search(class_searh, string_searh) {

    //get elements
    var class_searh_elements = document.getElementsByClassName(class_searh);
    //get string
    var string = string_searh.toString();

    //loop for each element
    for (var i = 0; class_searh_elements.length > i; i++) {

      //get the data on child element on 'class_searh_elements'
      var text_data = class_searh_elements[i].childNodes[0].data;

      //if maches add the class wich hides the element
      if (text_data.search(string) < 0) {
        class_searh_elements[i].classList.add('hidden');
        //if don't maches remove the class wich hides the element
      } else {
        class_searh_elements[i].classList.remove('hidden');
      }
    }
  }
</script>

<!--class that hides -->
<style>
  .hidden {   display: none;   }
</style>

<?php
//array example
$run_qry = [

  ['empid' => 1, 'fname' => 'john', 'lname' => 'john'],
  ['empid' => 2, 'fname' => 'mary', 'lname' => 'anne'],
  ['empid' => 3, 'fname' => 'mc', 'lname' => 'donalds'],
];

echo "<input type='text' name='string_seach' id='string_search' value='' onkeydown='search(\"elements_class\",this.value)' /> <hr>";

foreach ($run_qry as $row) {
  echo "<label class='elements_class'>" . $row['fname'] . " " . $row['lname'] . "<input  type='checkbox' name='emply[]' value='91" . $row['empid'] . "' /><br></label>";
}
?>


查看MySQLi语句,如“%$mySearchString%”,或者查看jquery过滤器搜索插件。没有人完全读过拉胡尔的问题。。。检查答案。@Rahul Teja,你试过了吗?