dongyi6195 2017-01-16 16:16
浏览 35
已采纳

如何制作分页表?

I'm using bootstrap and I have used a table to echo users data by using PHP, the problem is that there's a lot of results, so I want to show pagination below that table, and I want to do this with jQuery if possible? If not I guess I will go for PHP.

How could I do it? I have tried several plugins and different methods, but actually I'm a beginner and it didn't work smoothly for me.

One of the jQuery plugins I tried is simplePagination.js but nothing is working.

My code:

<table 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><?php echo $row['mem_uname']; ?></th>
            <td><?php echo $row['mem_email']; ?></td>
            <td><?php echo $row['mem_phone']; ?></td>
            <td>
                <a class="btn btn-danger option"
                href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
            </td>
        </tr>
    </tbody>
</table>
  • 写回答

1条回答 默认 最新

  • douke3442 2017-01-19 14:43
    关注

    You could use dataTables jQuery plugin which:

    • Is bootstrap friendly
    • Includes pagination, you would only need to tweak it's length via jQuery.

    See snippet below:

    $('#myTable').dataTable({
      "pageLength": 4
    });
    <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>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?