码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2016-03-03 06:49:37      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

刚才那几节课程里面将功能几乎都实现了出来,公众平台营销咨询系统最后一部分就是分页的实现了,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>

 

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

标签:

原文地址:http://www.cnblogs.com/leigood/p/5237160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!