|
|
|
ดึงข้อมูลจาก txt ไฟล์ แล้วแบ่งหน้า จากไฟล์ที่ให้ครับ พยามยามแก้แล้วก้ไม่ได้ |
|
|
|
|
|
|
|
เขียนให้ดูครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & Text File Pagination</title>
</head>
<body>
<?
$arrFile = null;
$strFileName = "thaicreate.txt";
$objFopen = fopen($strFileName, 'r');
if ($objFopen) {
while (!feof($objFopen)) {
$file = fgets($objFopen, 4096);
$arrFile[] = $file;
}
fclose($objFopen);
}
/*** Soft ***/
//rsort($arrFile); // DESC
//asort($arrFile); // ASC
$Num_Rows = count($arrFile);
$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)+1;
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="300" border="1">
<tr>
<th width="50"> <div align="center">No </div></th>
<th width="250"> <div align="center">Files </div></th>
</tr>
<?
$no = 1;
if($Page > 1)
{
$no = ($Per_Page * ($Page-1)) + 1;
}
for($i=$Page_Start;$i<=$Page_End;$i++)
{
?>
<tr>
<td><div align="center"><?=$no;?></div></td>
<td><?=$arrFile[$i-1];?></td>
</tr>
<?
$no++;
}
?>
</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 :
2016-02-09 13:19:05 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ อ.วิน
|
|
|
|
|
Date :
2016-02-10 06:26:11 |
By :
artnana |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|