Home > php教程 > PHP源码 > body text

php简单的分页程序

WBOY
Release: 2016-06-08 17:30:07
Original
1298 people have browsed it

下面我们来看看我自己写的一个简单的php分页代码哦,其实在php中分页比较在asp中分页容易的多,这也可能是因为mysql有强大的功能的吧,这样节省不少系统资源了

<script>ec(2);</script>

 

function newlista($action){
    $sql  ="Select * from gx_news  ";
    if( $action=='today' ){ $sql.=" where datediff(new_time,".date("Y-m-d").")     $result =mysql_query($sql) or die('fail1'.mysql_error());
    $rs  =mysql_fetch_array($result);
    $rdcount =mysql_num_rows($result);
    if($rdcount){
    $pagesize =15;
    $pagecount=($rdcount % $pagesize)?(int)($rdcount / $pagesize)+1:$rdcount/$pagesize;//统计总页面
    $page  =isset($_GET['page'])?$_GET['page']:1;//取得当前页面
    $start =($page>=1 && $page     $start =$start;
    $sql  =$sql." order by id desc limit $start,$pagesize";
    $bg  =1;
   
    //$resulte =mysql_query($sql) or die('fail'.mysql_error());
    $result =mysql_query($sql) or die(mysql_error());
  while($rs =mysql_fetch_array($result) ){
    if( $bg % 2 !=0){
      
      $style="class=color";
      
    }else{
    
      $;
     
    }
    
    echo "

  • ".$rs['new_title']."[".$rs['new_time']."]
  • ";
        $bg++;
      }
       echo '";
     }else{
       echo '暂时没有信息!';
     }

     }

    本人原创转载注明www.111cn.net/phper/php.html

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!