在我的分页代码中,我每页列出 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..
?>
这里有一些 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;
}
?>
第一页没有问题,但是当我转到第二页时,它又从1开始,但我希望它从6开始,我不知道如何实现它。我进行了搜索,但没有结果。事实上,我的英语水平有限,我想我不知道如何用合适的词来搜索它。感谢您的理解!
您需要更新查询以使用偏移量。 (** 抱歉,没注意到您使用的是速记 **)
我花了一点时间才明白问题的要点。 使用: $startno = $show + 1;
而不是: $firstrowno= 1;
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++;
}
?>
变量在访问服务器之间不会保留其状态。 (除非您存储它们并从会话中检索它们。