dongwei1263 2011-10-09 07:09
浏览 96
已采纳

PHP Ajax MySql分页

I am using AJAX Pagination for displaying my records in application from MySQL using PHP. I have done that successfully but just need one solution:

I need to display a Serial No while displaying records like:

----------------------------
S.No   Name       Country  
----------------------------
1      Sandeep    India  
2      Rahul      Japan  
3      Riya       China   
4      Sohan      India  
...
50     James      USA

If I have set to show 20 results per page while paginating the first page shows serial no. 1 to 20 , 2nd page shows serial no 1 to 20 and 3rd page shows serial no 1 to 10.

But I want to show serial no. 1 - 20 in first page , 21- 40 in second page , 41- 50 in 3rd page.

How can I do this in PHP?

Here is my code:

$ssql = $ssql_select.$ssql_where." order by reg_date desc LIMIT $Page_Start , $Per_Page";
$rs=mysql_query($ssql, $cn) or die("MySQL error: ".mysql_error());
$ctr = 1;
while ($row = mysql_fetch_object($rs)) {

    echo "<td align=center>".$ctr."</td>";
    echo "<td align=center>".$row->name."</td>";
    echo "<td align=center>".$row->country."</td>";
    $ctr++;
}
  • 写回答

1条回答 默认 最新

  • dongyin2390 2011-10-09 07:19
    关注

    Try

     ...
        while ($row = mysql_fetch_object($rs)) {
    
            echo "<td align=center>" . $ctr + $Page_Start . "</td>";
            echo "<td align=center>".$row->name."</td>";
            echo "<td align=center>".$row->country."</td>";
            $ctr++;
        }
     ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式