谁能帮我吗?我对使用 javascript 的 Pagination 生疏了,想在我的 php 网站上实现它。我正在尝试制作类似于此网站上的示例分页:,但就像我说的那样,我真的很生疏,它不会限制我的结果。例如。它看起来像这样:| 1 | 2 | 3 | 4 | 5 | 6 | ... |所有页面|,但我希望它更像网站之类的示例,有人可以帮我吗?
$num_of_result = mysql_num_rows($result);
$results_per_page = 10;
$pageNum = intval($_POST['pageNum']);
if($pageNum == "")
$pageNum = 0;
$limit = " LIMIT ".($pageNum*$results_per_page)." , ".($results_per_page)." ";
$sql .= $limit;
echo "
<script>
function setpage(num){
document.pageForm.pageNum.value = num;
document.pageForm.submit();
}
</script>";
echo "<form action='search_results.php' method='post' id='pageForm' name='pageForm' >";
foreach($_POST as $name => $value){
if($name != "pageNum"){
if(is_array($value)){
foreach($value as $element){
echo "<input type='hidden' name='".$name."[]' value='$element'>";
}
}
else
echo "<input type='hidden' name='$name' value='$value'>";
}
}
echo "<input type='hidden' name='pageNum' id='pageNum'>";
//echo show page links
if($num_of_result > $results_per_page){
//Get total pages
$pageCount = ($num_of_result / $results_per_page);
for($i=0; $i < $pageCount; $i++){
if($i == $pageNum)
$html[] = "<strong>".($i+1)."</strong>";
else
$html[] = "<a href='javascript: setpage($i);'>".($i+1)."</a>";
}
echo "Page: ";
echo @implode(' | ',$html);
if( $pageNum < ($pageCount-1) )
echo " | <a href='javascript: setpage(".($pageNum+1).");'>Next Page</a>";
}