$tbl_name="info"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 2;/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$targetpage = "pagination.php"; //your file name (the name of this file)
$limit = 2; //how many items to show per page
$page = $_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
$sql = "SELECT column_name FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\"> Previous <<</a>";
else
$pagination.= "<span class=\"disabled\"> Previous <<</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">Next >> </a>";
else
$pagination.= "<span class=\"disabled\">Next >> </span>";
$pagination.= "</div>\n";
}
$query1="select * FROM info order by id desc LIMIT $start, $limit";
$result1=mysql_query($query1);
if($_GET['page']!='' )
{
$i=$start+1;
}
else
{
$i='1';
}
$k=1;
while($row=mysql_fetch_array($result1))
{
?>
<tr>
<td>
<?php echo $k++; ?></td>
<td>
<td>
<?php echo $row["name"]; ?></td>
<td>
<?php echo $row["mobile_number"]; ?></td></td>
</tr>
<?php } ?>
</table>
<?php echo $pagination; ?>
</body>
</html>这是我在php...it中的分页代码,在一个页面上显示2个结果,因为限制是每个page...but 2,现在的问题是,当我单击分页加载另一个page...then时,它会加载下两个记录的第二个页面,但数字从1 ....what开始,我想要的是,当第一个页面显示两个记录时,它显示数字1和2,当我单击第二个页面时,在第二个页面上,它应该继续显示数字,并显示3 -4,而不是1,2....can有人能帮我吗?
发布于 2014-01-24 18:57:35
尝尝这个
$page_numbers =intval($total_pages‘’num‘/$limit)+1;
然后,在for循环中,您可以获得所有的页码。并且将ur页面id和最后一个id传递给分页u可以完全执行分页。
发布于 2015-08-17 18:25:46
var start = $("#start").val();
$(document).ready(function(){
var count = $("#count").val();
$.post("paginate.php",{start:start,count:count},function(get_page){
$("#newpage").load(get_page);
start += 10
})
});创建一个具有display:none的文本字段每页的值确保id等于start,value等于每页创建另一个文本字段并将其命名为count,仍显示隐藏值10
对于paginate.php
mysql_connect(username and password and host)
mysql_select_db(database name);
$start = $_POST['start'];
$count = $_POST['count'];
mysql_query("SELECT * FROM table WHERE yourclause='clause' ORDER BY id DESC LIMIT $start , $count ")https://stackoverflow.com/questions/21329195
复制相似问题