dongyiyu3953 2014-01-06 17:38
浏览 11

分页行编号

So I can't get this to work.

I have the variable $page which contains the current page, $total_pages which contain the total amount of pages and $limit which contains the max number of rows per page.

I have tried doing a lot of stuff but I just don't get it.

This is the latest thing I tried. It works for page 1 & 2 but then it just stops working

if ($page == 1) {
        $count = 1;
    } else {
        $count = $page * $limit/2 + 1;
    }

That code was above my while-loop which loops out the rows.

  • 写回答

2条回答 默认 最新

  • drvkf88226 2014-01-06 17:46
    关注

    This is :

    if ($page == 1) {
        $count = 1;
    } else {
        $count = ($page - 1) * $limit + 1;
    }
    

    It is equal to what you tried for $page = 1 or 2, that's why it worked. This is even shorter and works whaterver the value of $page :

    $count = ($page - 1) * $limit + 1;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败