zoukankan      html  css  js  c++  java
  • 实现“上一页”和“下一页"按钮

    简介:这是实现“上一页”和“下一页"按钮的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=327666' scrolling='no'> <?php  
    //本例子摘自phpbuilder.com  
    //稍加翻译  
    //<sprming@netease.com>  

    $limit=20; // 每页显示的行数  
    $numresults=mysql_query("select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER");//换成你所需要的sql语句  
    $numrows=mysql_num_rows($numresults);  

    // next determine if offset has been passed to script, if not use 0  
    if (empty($offset)) {  
    $offset=1;  
    }  

    // 得到查询结果  
    $result=mysql_query("select id,name,phone ".  
    "from TABLE where YOUR CONDITIONAL HERE ".  
    "order by WHATEVER limit $offset,$limit");  

    // 现在显示查询结果  
    while ($data=mysql_fetch_array($result)) {  
    // 在这里插入您要显示的结果以及样式  
    }  

    // 显示按钮  

    if ($offset!=1) { // bypass PREV link if offset is 1  
    $prevoffset=$offset-20;  
    print "<a href=\"$PHP_SELF?offset=$prevoffset\">上一页</a> &nbsp; \n";  
    }  

    // 计算页面数  
    $pages=intval($numrows/$limit);  

    // $pages now contains int of pages needed unless there is a remainder from division  
    if ($numrows%$limit) {  
    // has remainder so add one page  
    $pages++;  
    }  

    for ($i=1;$i<=$pages;$i++) { // 显示页数  
    $newoffset=$limit*($i-1);  
    print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";  
    }  

    // check to see if last page  
    if (!(($offset/$limit)==$pages) && $pages!=1) {  
    // not last page so give NEXT link  
    $newoffset=$offset+$limit;  
    print "<a href=\"$PHP_SELF?offset=$newoffset\">下一页</a><p>\n";  
    }  

    ?>  


    “实现“上一页”和“下一页"按钮”的更多相关文章 》

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/327666.html pageNo:12
  • 相关阅读:
    如何免费在 arm 官网上下载合适的手册
    ARM Cortex-A系列处理器性能分类比较
    USB OTG有关协议
    fseek在 fopen 带有'a'模式下不起作用
    Zynq 7000的3种IO
    多核处理器与MP架构
    Vim常用插件命令手册
    剑指 Offer 07
    Leetcode 94
    剑指offer 27
  • 原文地址:https://www.cnblogs.com/ooooo/p/2250872.html
Copyright © 2011-2022 走看看