• 夺命雷公狗---微信开发35----公众平台营销咨询系统4(分页)


    刚才那几节课程里面将功能几乎都实现了出来,公众平台营销咨询系统最后一部分就是分页的实现了,show_info.php这里修改下代码分页即可实现出来,代码如下所示:

    <?php
        //链接数据库
        $connect = mysql_connect('localhost','root','root');
        mysql_select_db('wxdb',$connect);
        mysql_query('set names utf8');
        //分页开工咯,先取个别名counts
        $sql = "select count(*) as counts from zx_info";
        $res = mysql_query($sql);
        $row = mysql_fetch_assoc($res);
        //这里的$row_num是总的咨询条数
        $row_num = $row['counts'];
        //我们规定每页显示5条记录
        $page_size = 5;
        //计算总页数
        $page_count = ceil($row_num/$page_size);
        //接收当前用户点击的是第几页
        $page_num = $_GET['page_num'];
        //判断$page_num是否为空,如果是空的默认给他一个1
        if(empty($page_num)){
            $page_num = 1;
        }
        //计算从那条记录开始获取
        $begin = ($page_num-1)*$page_size;
        $sql = "select * from zx_info order by id desc limit {$begin},{$page_size}";
        $info_res = mysql_query($sql);
    ?>
    <!doctype html> 
    <html> 
        <head> 
            <meta charset="utf-8">
            <title>公众平台营销咨询系统</title>
            <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
            <meta name="apple-mobile-web-app-capable" content="yes">
            <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
            <meta name="format-detection" content="telephone=no"> 
            <link href="./jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"> 
            <script src="./jquery-1.6.4.min.js" type="text/javascript"></script> 
            <script src="./jquery.mobile-1.0.min.js" type="text/javascript"></script> 
        </head> 
        <body>
            <div data-role='page' id='page3'>
                <div data-role='header'>
                    <h1>公众平台营销咨询系统</h1>
                </div>
                
                <div data-role='content'>
                    <ul data-role='listview'>
                        <?php
                            $row = array();
                            while($row = mysql_fetch_assoc($info_res)){ 
                        ?>
                            <li>
                                <a href="/reply_view.php?id=<?php echo $row['id']; ?>"><?php echo $row['zx_info']; ?>
                                <p class="ui-li-aside">回复咨询</p></a>
                            </li>
                        <?php } ?>
                    </ul>
                </div>
                
                <!--分页的按钮开始-->
                <div data-role="controlgroup" data-type="horizontal">
                <?php
                    if($page_num!=1 && $page_num>1){ ?>
                        <a href="/show_info.php?page_num=<?php echo $page_num-1; ?>" data-role="button">上一页</a>
                    <?php } ?>
                <?php
                    if($page_count > $page_num){ ?>
                        <a href="/show_info.php?page_num=<?php echo $page_num+1; ?>" data-role="button">下一页</a>
                    <?php } ?>
                </div>
                <!--分页的按钮结束-->
            </div>
        </body> 
    </html>
  • 相关阅读:
    ubuntu 卸载干净软件(包括配置文件)
    Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?
    linux watch 命令
    [转]如何成为优秀的程序员?
    【转】css浮动元素的知识
    Hierarchical data in postgres
    【转】supervisord使用
    手动安装pip
    zoj1649-Rescue (迷宫最短路径)【bfs 优先队列】
    poj3278-Catch That Cow 【bfs】
  • 原文地址:https://www.cnblogs.com/leigood/p/5237160.html
Copyright © 2020-2023  润新知