如何制作分页表?

时间:2017-01-16 16:16:14

标签: php jquery twitter-bootstrap pagination

我使用bootstrap并且我使用表来使用PHP来回显用户数据,问题是有很多结果,所以我想在该表下面显示分页,我想要如果可能,用jQuery做这个?如果不是,我想我会选择PHP。

我怎么能这样做? 我尝试了几种插件和不同的方法,但实际上我是初学者,但对我来说并不顺利。

我尝试过的一个jQuery插件是<?php // input: textfile with one bitly shortened url per line $plain_urls = file_get_contents('in.txt'); $bitly_urls = explode("\r\n", $plain_urls); // output: where should we write $w_out = fopen("out.csv", "a+") or die("Unable to open file!"); foreach($bitly_urls as $bitly_url) { $c = curl_init($bitly_url); curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($c, CURLOPT_HEADER, 1); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 20); // curl_setopt($c, CURLOPT_PROXY, 'localhost:9150'); // curl_setopt($c, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); $r = curl_exec($c); // get the redirect url: $redirect_url = curl_getinfo($c)['redirect_url']; // write output as csv $out = '"'.$bitly_url.'";"'.$redirect_url.'"'."\n"; fwrite($w_out, $out); } fclose($w_out); ,但没有任何效果。

我的代码:

simplePagination.js

1 个答案:

答案 0 :(得分:1)

您可以使用 dataTables jQuery plugin

  • 引导友好
  • 包括分页,你只需要通过jQuery调整它的长度。

请参阅下面的代码段:

&#13;
&#13;
$('#myTable').dataTable({
  "pageLength": 4
});
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js"></script>
<table id="myTable" class="table table-striped">
  <thead>
    <tr>
      <th width="30%">User Name</th>
      <th width="35%">Email</th>
      <th width="30%">Phone</th>
      <th width="5%">Option</th>
    </tr>
  </thead>
  <tbody>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
    <tr id="users">
      <th>TEST</th>
      <td>TEST</td>
      <td>TEST</td>
      <td>
        <a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
      </td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;