กลับไปหน้าหลัก
ตัวอย่างโค้ด แสดงเลขหน้า
ตัวอย่างโค้ดการใช้งาน
<?php
Function page_display_results ($rowResultsArray, $pageNum=1, $rowsPerPage=10, $extraHTMLParms="")
{


global $PHP_SELF;
$output = "";
// $pageNum starts at 1.
$startRow = ($pageNum - 1) * $rowsPerPage;
$stopRow = $startRow + $rowsPerPage;
for ($i = $startRow; ($i < count($rowResultsArray)) && ($i < $stopRow); $i++){
    $str_result.= "<br>$rowResultsArray[$i]"; //show result
}
$url = "$PHP_SELF?$extraHTMLParms";

$numPages = ceil(count($rowResultsArray) / $rowsPerPage);

if ($pageNum != 1)
    $output .= "<a href=\"$url&pageNum=" . ($pageNum-1) . "\">previous</a> "; // show previous page

for ($i = 1; $i < $numPages+1; $i++){
    if ($pageNum == $i) $output .= "<b>$i</b> "; // show current page
    else $output .= "<a href=\"$url&pageNum=" . $i . "\">$i</a> ";
}

if ($pageNum < (int)$numPages)
$output .= "<a href=\"$url&pageNum=" . ($pageNum+1) . "\">next</a> "; // show next page

return $output.$str_result;

}
if (!isset($pageNum)) $pageNum = 1;
$result =array("aaaa","bbbb","cccc","dddd","eeee");
print page_display_results ($result, $pageNum, 2 );
?>