简体   繁体   English

PHP分页-如何在后续页面中继续编号

[英]Php paging - How to continue numbering in following pages

In my pagination code, I list 5 buildings per page and number them from 1 to 5, 在我的分页代码中,我每页列出5座建筑物,并将它们从1编号为5,

<?php
$page = intval($_GET['page']);
if(!$page) $page = 1;
$totalno=mysql_num_rows(mysql_query("SELECT M1_ID FROM M1Buildings WHERE M1_Cat2 BETWEEN 3 AND 4 && M1_Status=5"));
$limit = 5;
$show = $page * $limit - $limit;
$buildinglist = mysql_query("SELECT * FROM M1Buildings  WHERE M1_Cat2 BETWEEN 3 AND 4 && M1_Status=5 ORDER BY M1_Height DESC LIMIT $show,$limit",$con);
$firstrowno=1;//This will be 1 for page 1, 6 for page 2, 11 for page 3 etc..
?>

Some html code here, then: 一些HTML代码,然后:

<?php
$startno=1;//This is the number of each row, starting from 1
while ($rowblist = mysql_fetch_array ($buildinglist))
{
echo '<tr>
        <td>'.$startno.'</td>
<td>Some information here</td>
<td>Some information here</td>
    </tr>';
    $startno++;
    $firstrowno+5;
}
?>

There is no problem in first page, but when I pass to page 2, it again starts from 1, but I want it starts from 6, I couldn't get how can I achieve it. 第一页没有问题,但是当我进入第2页时,它又从1开始,但是我希望它从6开始,我无法实现。 I've performed a search, but no result. 我进行了搜索,但没有结果。 Actually with my limited english, I can't know how to search it with proper words, I guess. 实际上,我的英语有限,我不知道该如何用合适的词来搜索它。 Thanks for your understanding! 感谢您的理解!

You need to update your query to use offset. 您需要更新查询以使用偏移量。 (** Sorry, didn't notice you were using the shorthand **) (**对不起,没有注意到您使用的是速记**)

Took a moment for me to get the gist of the question. 我花了一点时间来理解这个问题的要点。 Use: $startno = $show + 1; 使用:$ startno = $ show + 1;

instead of: $firstrowno= 1; 而不是:$ firstrowno = 1;

After the HTML: 在HTML之后:

<?php
while ($rowblist = mysql_fetch_array ($buildinglist))
{
echo '<tr>
        <td>'.$startno.'</td>
<td>Some information here</td>
<td>Some information here</td>
    </tr>';
    $startno++;
}
?>

The variables do not retain their state between trips to the server. 变量在两次访问服务器之间不会保留其状态。 (Unless you store them and retrieve them from sessions. (除非您存储它们并从会话中检索它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM