您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql+php分页类(已测)_PHP教程

2025/12/7 18:05:28发布20次查看
复制代码 代码如下:
php4)     
   需要查询的结果句柄,当前页码,每页记录数     
   like:  $f->mysql_pager($result, 1, 15);     
*/
function mysql_pager( $result, $current_page, $results_per_page ) {
if(!$result){      
        echo 数据库未运行,结果集错误
\n;        
        return;      
        }
$this->result = $result;
if(!$current_page || $current_page         $this->page = 1;      
   else $this->page = $current_page;
if(!emptyempty($results_per_page))        
      $this->results_per_page = $results_per_page;
$numrows = @mysql_num_rows($this->result);        
   if(!$numrows) {      
      echo 查询结果为空.
\n;      
      return;      
      }
$this->total_pages = ceil($numrows / $this->results_per_page);        
}
/*       
  下面是打印内容的函数,可以不用,也可以根据自己的需要扩展     
  这里只是打印出id     
*/
function print_paged_results() {        
    echo \n;      
    $start = ($this->page - 1) * $this->results_per_page;      
    mysql_data_seek($this->result, $start);      
    $x = 0;      
    for($i = 1; $i results_per_page && $row = @mysql_fetch_array($this->result); $i++) {      
        if($x++ & 1) $bgcolor = #f2f2ff;      
        else $bgcolor = #eeeeee;
echo . $row[id] . 
;            
        // 编辑这部分输出任何您想要的html
}
echo 
\n;      
}
/*       
  下面是打印页码和链接的函数     
  在我们需要显示页码的地方调用     
*/
function print_navigation() {      
    global $php_self;
echo ;
for($i = 1; $i total_pages; $i++) { #loop to print >        
       if($i == 1 && $this->page > 1)  #prints the           echo page - 1).\ onmouseover=\status=previous page;return true;\ onmouseout=\status= ;return true;\>?;
if($i == $this->page)  #doesnt print a link itself, just prints page number       
          echo  $i ;
if($i != $this->page)  #other links that arent this page go here       
          echo  $i ;
if($i == $this->total_pages && $this->page != $this->total_pages)  #  link for next page >>  (not on last page)        
          echo page + 1).\ onmouseover=\status=go to the next page;return true;\ onmouseout=\status= ;return true;\>?;        
       }
echo 
\n;        
  }
}
/*     
   mysql_connect($server, $uname, $pass );     
   mysql_select_db($db);     
   $result= @mysql_query(select * from table);
$p = new mysql_pager( $result, $page=$_get[page], 10 );     
   $p->print_navigation();     
   $p->print_paged_results();     
   $p->print_navigation();     
*/      
?>
http://www.bkjia.com/phpjc/318727.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/318727.htmltecharticle复制代码 代码如下: ?php /* mysql_pager.class.php 三个参数。mysql_query()的结果,url变量page,您要的每页记录数 例子在这个文件底部 淡水河边整理测...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product