使用jquery插件和php进行动态数据表分页


Pagination with dynamic data tables using jquery plugin and php

我试图从postgresql数据库分页我的动态数据表。数据被加载到页面上,但是当它加载时,分页不起作用。另外,如果我放入静态数据,它也可以工作。

我使用jquery插件jquery.js和jquery. datatables .js

我认为我的jquery代码没有得到表,不确定

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function {
            $('#example').dataTable( {
                "itemsOnPage": 8,
                "sPaginationType": "full_numbers",
                "bPaginate": true,
                "bLengthChange": true,
                "bFilter": true
            }
            );
        } );
    </script>

和这是我的表

    <table cellpadding="0" cellspacing="0" id="example">
    <thead>
     <tr>
       <th width="6%"><strong>col1</strong></th>
       <th width="20%"><strong>col2</strong></th>
       <th width="30%"><strong>col3</strong></th>
     </tr>
    </thead>
    <tbody class="selects">
     <?php
      $count=0;
      while($row=pg_fetch_array($result))
      {?>
     <tr>
     <td><?php echo $row['col1']; ?></td>
     <td><?php echo $name =$row['col2']; ?></td>
     <td><?php echo $type =$row['col3']; ?></td>
     <?php $count=$count++; ?>
     </tr>
    <?php  }
   ?>
   </tbody>
   </table>

你必须把$('#example').dataTable()改成$('#example').DataTable(),就这样。