使用PHP&进行Bootstrap分页的MySQL [英] Bootstrap Pagination using PHP & MySQL

查看:92
本文介绍了使用PHP&进行Bootstrap分页的MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Bootstrap的新手,我试图在页面的某一部分上实现分页,以正确表示数据.谁能帮忙吗?

I am kind of new to Bootstrap, I am trying to implement pagination on one of the sections in my page to represent the data properly. Can anyone please help?

这是代码现在的外观快照.如何实现分页以便仅显示10条记录?谢谢.

Here is a snapshot of how the code looks right now. How can I implement pagination so that only 10 records are displayed? Thanks.

<section class="success" id="all-confessions">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2>All Confessions</h2>
                <hr class="star-light">
            </div>
        </div>
        <div class="row">
            <div class="row text-left">
                <?php
                $allconfession = mysql_query("SELECT * FROM collection ORDER BY date DESC");

                while($result2 = mysql_fetch_array($allconfession)) {
                    $id = $result2['id'];
                    ?>
                    <div class="col-md-3 col-md-offset-1">
                        <h5>#<?php echo $id; ?></h5>
                    </div>
                    <div class="col-md-10 col-md-offset-1">
                        <p class="para-confess">
                            <?php
                            echo $result2['type'] ." from ". $result2['college'] ." of ". $result2['department'] ." confessed ". $result2['confession']; 
                            ?>
                        </p>
                        <div class="text-left">
                            <?php
                            if(isset($_COOKIE['uname'])) {
                                ?>
                                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                                    <input type="text" name="cid" style="display: none;" value="<?php echo $id; ?>">
                                    <button type="submit" class="btn btn-success fa fa-thumbs-up" name="like"> Cool</button>
                                    <button type="submit" class="btn btn-warning fa fa-thumbs-down" name="dislike"> WTF</button>
                                </form>
                                <?php
                            }
                            ?>
                        </div>
                        <div class="text-right">
                            <i class="fa fa-thumbs-o-up"> 
                                <?php 
                                $likes = mysql_query("SELECT COUNT(*) FROM activity WHERE cid = $id AND ld = 1");
                                $alikes = mysql_fetch_row($likes);
                                echo $alikes[0]; 
                                ?> 
                            </i> &nbsp;
                            <i class="fa fa-thumbs-o-down"> 
                                <?php 
                                $dislikes = mysql_query("SELECT COUNT(*) FROM activity WHERE cid = $id AND ld = 0");
                                $adislikes = mysql_fetch_row($dislikes);
                                echo $adislikes[0]; 
                                ?> 
                            </i>
                        </div>
                        <hr/>
                    </div>
                    <?php
                }
                ?>
            </div>
        </div>
    </div>
</section>

推荐答案

您距离还很遥远.

至少,您需要执行以下操作.

At the very minimum, you need to do the following.

  1. 您需要创建一个变量,该变量确定每页显示的项目数.
  2. 您需要将该变量乘以页码,以获取要在查询中抵消的记录数.
  3. 您需要使用从上述计算中获得的数字来抵消查询结果,并将查询限制为要显示的项目数.
  4. 您需要计算总项目数,然后将其除以每页的项目数,以获取要在分页中显示的总页数.

以下是一些我与Bootstrap结合使用的简单分页代码.

Here is some simple pagination code that I've used many times in conjunction with Bootstrap.

http://www.a2zwebhelp.com/php-mysql-pagination

只需省略样式,然后将Bootstrap类应用于元素.但是,您不能只添加静态html并期望它在没有任何后端逻辑的情况下就可以工作. Bootstrap仅提供一种样式设置分页样式,但是您必须构建它.

Just omit the styles and apply Bootstrap classes to the elements. But you cannot just add static html and expect it to work without any kind of backend logic to it. Bootstrap only provides a way to style the pagination, but you have to build it.

这篇关于使用PHP&amp;进行Bootstrap分页的MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆