PHP多行多列分页

前段时间发了一个PHP分页的,后来研究了下多列的,今天再发上去

 

<? php  require_once ( ' Connections/lr.php ' );  ?>
<? php  require_once ( ' pageconfig.php ' );  ?>
<? php
 
// 设定每一页显示的记录数

$pagesize = $meiyegeshu ;

// 取得记录总数$rs,计算总页数用
mysql_select_db ( $database_lr ,   $lr );
$rs = mysql_query ( " select count(*) from product " );

$myrow   =   mysql_fetch_array ( $rs );

$numrows = $myrow [ 0 ];

// 计算总页数

$pages = intval ( $numrows / $pagesize );

if  ( $numrows % $pagesize )

$pages ++ ;

// 设置页数

if  ( isset ( $_GET [ ' page ' ])){

       
$page = intval ( $_GET [ ' page ' ]);

       }

else {

// 设置为第一页       

$page = 1 ;

}

// 计算记录偏移量

$offset = $pagesize * ( $page   -   1 );

// 读取指定记录数

       
$rs = mysql_query ( " select * from product order by articleid limit $offset,$pagesize " );

       
if  ( $myrow   =   mysql_fetch_array ( $rs ))

{

$i = 0 ;
// 如果$url使用默认,即空值,则赋值为本页URL:
if ( ! $url ){  $url = $_SERVER [ " REQUEST_URI " ];}
// URL分析:
$parse_url = parse_url ( $url );
$url_query = $parse_url [ " query " ];  // 单独取出URL的查询字串
if ( $url_query ){
// 因为URL中可能包含了页码信息,我们要把它去掉,以便加入新的页码信息。
//这里用到了正则表达式,请参考“PHP中的正规表达式”(http://www.pconline.com.cn/pcedu/empolder/wz/php/10111/15058.html)

$url_query = ereg_replace ( " (^|&)page=$page " , "" , $url_query );

// 将处理后的URL的查询字串替换原来的URL的查询字串:
$url = str_replace ( $parse_url [ " query " ] , $url_query , $url );

// 在URL后加page查询信息,但待赋值: 
if ( $url_query $url .= " &page " else   $url .= " page " ;
}
else  {
$url .= " ?page " ;
}

?>

< table border = " 0 "  width = " 100% " >

  
  
< tr >
  
<? php
$j = 0 ;
do  {

$j = $j + 1 ;
$i ++ ;
$w = $myrow [ ' swidth ' ];
$h = $myrow [ ' sheight ' ];
$m = $w / $smallpic_width ;
$n = $h / $smallpic_width ;

                
if  ( $w >= $smallpic_width  or  $h >= $smallpic_width ){
                    
if  ( $m > $n ) {
                       
$w1 = $smallpic_width ;
                       
$h1 = $h / $m ;}
                    
elseif  ( $m < $n ) {
                       
$h1 = $smallpic_width ;
                       
$w1 = $w / $n ;}
                    
else {
                       
$w1 = $smallpic_width ;
                       
$h1 = $smallpic_width ;
                       }
                    
                }
else {
                    
$w1 = $w ;
                    
$h1 = $h ;
                };
$pwidth = 100 / $meihanggeshu ;
?>

 


< td align = " center "  width = " <?php echo $pwidth?>% "  height = " 120 "  valign = " top " >< table width = " 100% "  border = " 0 "  cellspacing = " 0 "  cellpadding = " 0 "  align = " center " >
  
< tr >
    
< td align = " center " >< img src = " <?php echo $myrow['smallpic']?> "  width = " <?php echo $w1?> "  height = " <?php echo $h1?> " /></ td >
  
</ tr >
  
< tr >
    
< td align = " center " ><? php  echo   $myrow [ ' product_id ' ] ?></ td >
  
</ tr >
</ table >
</ td ><? php  if  ( $j   %   $meihanggeshu == 0 ) { ?>
  
</ tr >
<? php }  ?>



<? php

}

while  ( $myrow   =   mysql_fetch_array ( $rs ));

echo   " </table> " ;

}

echo   " <div align='center'>Total&nbsp; " . $pages . " &nbsp;pages( " . $page . " / " . $pages . " ) " ;

// for ($i=1;$i< $page;$i++)

//echo "<a href='?page=".$i."'>[".$i ."]</a>  ";

//echo "[".$page."]";

//for ($i=$page+1;$i<=$pages;$i++)

//echo "<a href='?page=".$i."'>[".$i ."]</a>  ";


$first = 1 ;

$prev = $page - 1 ;

$next = $page + 1 ;

$last = $pages ;
if  ( $page   ==   1 )
{
echo   " First&nbsp; " ;
}
else {
echo   " <a href=' " , $url , " = " . $first . " '>First</a>   " ;
}
if  ( $page   ==   1 ){
echo   " Pre&nbsp; " ;}
else {
echo   " <a href=' " , $url , " = " . $prev . " '>Pre</a>   " ;
}
if  ( $pages > $page ){
echo   " <a href=' " , $url , " = " . $next . " '>Next</a>   " ;
}
else {
echo   " Next&nbsp; " ;}
if  ( $pages > $page ){
echo   " <a href=' " , $url , " = " . $last . " '>Last</a>   " ;
}
else {
echo   " Last&nbsp; " ;}


echo   " <select name=change onchange='window.location="$url="+this.value'> " ;
for  ( $i = 1 ; $i <= $pages ; $i ++ ){
if ( $i == $page echo " <option value='$i' selected>$i/$pages</option> " ;
else   echo " <option value='$i'>$i/$pages</option> " ;
}
echo " </select> " ;
echo   " </div> " ;

?>

 用到了几个变量,分别是$meiyegeshu,$meihanggeshu读拼音就知道是什么了,呵呵。

你可能感兴趣的:(PHP)