|
 |
|
อยากสอบถามเรื่องการรับค่า php กับ array มาเพื่อทำการแบ่ง page เพื่อแสดงผลเป็นหน้า ครับ |
|
 |
|
|
 |
 |
|
อยากสอบถามเรื่องการรับค่า array มาเพื่อทำการแบ่ง page ครับ
ช่วยแนะนำวิธีการแบ่ง page โดยใช้ค่าที่ได้จาก array มา count เพื่อแบ่งจำนวนเพจหน่อยครับ
เช่น
Code (PHP)
array("A,B,C,D,E,F,G,H,I,J,K");
สมมุติต้องการให้แบ่ง 5 array ต่อ 1 หน้า ไม่ทราบว่าพอมีหลักการคิดหรือวิธีการอย่างไรบ้างครับ
ใช้วิธีการ Count แล้ว Break หรือเปล่าครับ
พอจะมีตัวอย่างไหมครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-01-28 11:30:12 |
By :
asustak |
View :
1169 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลืมไปครับ ต้องส่งค่าเบื้องหลังนะครับ
|
 |
 |
 |
 |
Date :
2012-01-28 11:46:17 |
By :
asustak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
</head>
<body>
<?
for($i=0;$i<=30;$i++)
{
$arr[$i] = $i * 10;
}
$Num_Rows = count($arr) - 1;
$Per_Page = 5; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="200" border="1">
<tr>
<th width="100"> <div align="center">Index </div></th>
<th width="100"> <div align="center">Value </div></th>
</tr>
<?
for($i=$Page_Start;$i<$Page_End;$i++)
{
?>
<tr>
<td><div align="center"><?=$i?></div></td>
<td><?=$arr[$i];?></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
?>
</body>
</html>

|
 |
 |
 |
 |
Date :
2012-06-14 10:08:18 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|