如何使用php从db填充html中的数据表

时间:2017-05-26 13:07:26

标签: javascript php ajax

我想用php替换java脚本以从db填充数据表 或者只是如何使用php从mysql数据库填充此表。 这是数据表: alladmins.php:

  <div class="col-xs-12">
  <div class="box">
  <div class="box-header">
  <h3 class="box-title">Admins</h3>
  </div>
  <!-- /.box-header -->
   <div class="box-body">
   <table id="adminTable" class="table table-bordered table-striped">
    <thead>
    <tr>
      <th>ADMIN ID</th>

      <th>USER NAME</th>

    <th>Password</th> 

   <th>Delete</th>

     </tr>
     </thead>
     <tbody id="ad">
     </tbody>
     <tfoot>
     <tr>
      <th>ADMIN ID</th>
       <th>USER NAME</th>
   <th>Password</th> 

  <th>Delete</th>

    </tr>
    </tfoot>
  </table>
   </div>
   <!-- /.box-body -->
   </div>
 </div>
    <!-- /.col -->
<script>createTable('#adminTable');</script> 

这是index.php中的脚本:

<script>
 var createTable = function(el){
   if ( $.fn.DataTable.isDataTable(el) ) {
     $(el).DataTable().destroy();
   }


 // table:  "#adminTable",
    $(el+' tbody').empty();
    var arrayOfAdmins = [{id:1,username:"asdasd",password:"asd"},
   {id:1,username:"asdasd",password:"asd"}];

    for (i=0; i<arrayOfAdmins.length;i++){
      $("#adminTable").append(

                 '<tr><td>'+ arrayOfAdmins[i].id
            +'</td><td>'+ arrayOfAdmins[i].username
            +'</td><td>'+ arrayOfAdmins[i].password
            +'</tr>'
  );}

 $(el).DataTable();

 };




  $('.tableSearch').val('a').trigger('#adminTable');

  $(document).ready(function(e){

    var navigate = function(location){
      $('#appMain').load(location,function(){

      });
    };

   /* NAVIGATION */
    $('ul.treeview-menu a').on('click',function(e){
     e.preventDefault();
      var location = $(e.target).attr('href');
      navigate(location);
     });

    navigate('templates/index2.php');
  });
  </script>

0 个答案:

没有答案