javascript - 数据库表过滤

标签 javascript php jquery mysql ajax

更新:抱歉,我是新来的,所以我不知道指南

这就是我到目前为止所做的

<!DOCTYPE HTML>
<html>
<head>
 <meta charset="utf-8">
 <title>AJAX filter demo</title>
</head>

<body> 
  <h1>Temporary Database</h1>

   <table id="employees">
    <thead>
    <tr>
         <th>ID</th>
      <th>Name</th>
      <th>Age</th>
      <th>Address</th>
      <th>Car</th>
      <th>Language</th>
      <th>Nights</th>
      <th>Student</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>

    <script src="http://code.jquery.com/jquery-latest.js"></script> 
     <script>
    function makeTable(data){
     var tbl_body = "";
      $.each(data, function() {
        var tbl_row = "";
        $.each(this, function(k , v) {
          tbl_row += "<td>"+v+"</td>";
        })
        tbl_body += "<tr>"+tbl_row+"</tr>";                 
      })

      return tbl_body;
  }

  function updateEmployees(){
    $.ajax({
      type: "POST",
      url: "submit.php",
      dataType : 'json',
      cache: false,
      success: function(records){
        $('#employees tbody').html(makeTable(records));
      }
      });
      }

    updateEmployees();
   </script> 
 </body> 
  </html>

现在输出关于客户端过滤的表格,我认为这就是我正在寻找的。我将如何使用下拉列表过滤每一列以输出特定数据,这与我有一个复选框不同? 谢谢

最佳答案

使用PHP生成表格和html,然后可能使用jquery插件https://datatables.net/ ,它允许您使用 javascript 和 jquery 轻松创建动态表。这将为您节省大量时间和精力。

关于javascript - 数据库表过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996052/

相关文章:

javascript - 仅在服务器 : Restful service + angularjs 上保存更改的对象

php - 了解大型 mysql 数据关系

php - 使用 PHP 删除网站上的文件?

javascript - Google Maps Api 未将 map 显示到 div 中

javascript - 追加到元素不起作用

javascript - 从<td>内的<span>属性获取值

javascript - 使用 AngularJS ng-repeat 维护显示的结果数

javascript - 如何清除 React.js 中的状态?

php - Magento 2.2.1 无法保存产品 - 类型推断期间发生错误缩小。请在 bugs.php.net 上提交错误报告

jquery - 无法在 jquery UI 对话框中设置输入字段的值