数据库表过滤

时间:2016-06-23 15:35:47

标签: 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>

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

1 个答案:

答案 0 :(得分:0)

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