0

在我的分页代码中,我每页列出 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;
}
?>

第一页没有问题,但是当我传递到第2页时,它又从1开始,但我希望它从6开始,我不知道如何实现它。我进行了搜索,但没有结果。实际上,我的英语有限,我猜我不知道如何用适当的词搜索它。感谢您的理解!

4

1 回答 1

1

您需要更新查询以使用偏移量。(** 抱歉,没有注意到您使用的是速记 **)

我花了一点时间来了解问题的要点。使用:$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++;
}
?>

变量在访问服务器之间不会保留它们的状态。(除非您存储它们并从会话中检索它们。

于 2013-01-28T00:06:42.720 回答