|
 |
|
ช่วยดูโค๊ดแบ่งหน้าให้หน่อยครับ มันไม่ตัดขึ้นหน้าใหม่ -*- |
|
 |
|
|
 |
 |
|
โค๊ดของผม มันไม่ยอมตัดหน้าให้ แต่มี หน้าขึ้นมา สมมุติ เรามีข้อมูล 10 แถว เราจะตัดแบ่ง ให้แสดง หน้า ละ 5 แถว มันกลับแสดงหน้า แรก10แถว แต่มีหน้า 2 เพิ่มขึ้นมา พอกดไปหน้า 2 ก็ยังแสดงข้อมูล หน้าแรกอยู่ ช่วยผมดูโค๊ดหน่อยครับ -.-
Class page
Code (PHP)
<?
class pager
{
function pagerlib($rpp,$count,$href,$page=1)
{
if($page<1)$page=1;
$pages=ceil($count/$rpp);
if($page>1)$page1="<a href=\"{$href}".($page-1)."\" class=\"page1\" >< previous</a>";
if($page<$pages&&$pages>1)$page2="<a href=\"{$href}".($page+1)."\" class=\"page1\" >next ></a>";
if($count)
{
$pagerarr=array();
$start_p=($page>5?$page-5:0);
$stop_p=$start_p+10;
for ($i=1;$i<=$pages; $i++)
{
if (($i!=$pages&&$i!=1)&&($start_p>$i||$stop_p<$i))
{
if(!$dotted)$pagerarr[]=" | ";
$dotted=true;
continue;
}
$dotted=false;
if ($i!=$page)
{
$pagerarr[]="<a href=\"{$href}$i\" class=\"page1\" >$i</a>";
}else{
$cls = ($pages > 1)? 'page2' : 'page1';
$pagerarr[]="<b class='".$cls."' >$i</b>";
}
}
$pager=join("",$pagerarr);
}
$pagertop="<div align=\"right\" >$page1$pager$page2</div>";
return array($pagertop,"LIMIT ".(($page-1)*$rpp).", $rpp");
}
?>
Function
Code (PHP)
<?
function getProductpage($pid ,$per,$page)
{
global $conn;
$pager = new pager();
$perpage = empty($per) ? 2 : $per;
$pathurl = '';
if ($count = &$conn->GetOne("SELECT count(*) as countrow FROM product WHERE brand_id ='$pid' ")) {
list($pg,$limit)= $pager->pagerlib($perpage,$count,$pathurl.'?pageid='.$pid.'&view='.$perpage.'&page=',$page);
$result = &$conn->Execute( "SELECT * FROM product WHERE brand_id = '$pid' ");
while (!$result->EOF) {
$refs[$result->fields['id']]['id'] = $result->fields['id'];
$refs[$result->fields['id']]['name'] = $result->fields['name'];
$refs[$result->fields['id']]['detail'] = $result->fields['detail'];
$refs[$result->fields['id']]['picture1'] = $result->fields['picture1'];
$refs[$result->fields['id']]['picture2'] = $result->fields['picture2'];
$refs[$result->fields['id']]['brand_id'] = $result->fields['brand_id'];
$result->MoveNext();
}
}
return array('value' => $refs, 'pager' => $pg);
}
?>
Code
Code (PHP)
<?
$page = 1;
$viewid = !empty($_GET['view'])? $_GET['view'] : 5;
$page = !empty($_GET['page'])? $_GET['page'] : 1;
$a = getProductpage($_GET['pageid'],$viewid ,$page);
foreach($a['value'] as $id => $value){
echo "<img src=\"admin/picture/{$value['picture1']}\"/>";
$iLoop++ ;
if ( $iLoop % 4 == 0 ) {echo "</tr><tr>" ;}
}
echo $a['pager'];
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-03-27 10:17:21 |
By :
rakket |
View :
1134 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้น ก็เปลี่ยนดีกว่า อิอิ
|
 |
 |
 |
 |
Date :
2011-03-27 11:06:08 |
By :
rakket |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|