【问题标题】:First record not picked up in pagination script (despite the fact it is set to show all records > NOW() as query)第一条记录未在分页脚本中获取(尽管它设置为显示所有记录 > NOW() 作为查询)
【发布时间】:2010-10-18 11:26:51
【问题描述】:

这是我一直在处理的分页脚本:

http://pastebin.com/4mpjdWKD

这是显示记录的查询页面 - 但它省略了第一条记录:

http://pastebin.com/kJZy9fv0

实际查询是这样的:

    <?php
   //Require the file that contains the required classes
   include("pmcPagination.php");

   //PhpMyCoder Paginator
   $paginator = new pmcPagination(20, "page");

   //Connect to the database
   mysql_connect("localhost","root","PASSWORD HIDDEN FOR SECURITY REASONS");
   //Select DB
   mysql_select_db("housemde");

   //Select only results for today and future   
        $result = mysql_query("SELECT * FROM housemd WHERE expiration > NOW() 
        order by airdate;");
        $recordCount = mysql_num_rows($result);


   //You can also add reuslts to paginate here
   mysql_data_seek($result,0) ;
           while ($row = mysql_fetch_array($result))
   {
    $paginator->add(new paginationData($row['programme'],
               $row['channel'],
               $row['airdate'],
               $row['expiration'],  
                           $row['episode'],  
                           $row['series'],  
                           $row['epno'],  
               $row['setreminder']));
   }
  ?>

而且日期都在未来,甚至要显示第一条记录,我必须在 PhpMyadmin 中复制它 - 那么我的脚本有什么问题?

是否与mysql_fetch_array有关,如果是,我需要在哪里修复脚本?

无论如何,这里是来自数据库的数据,所有显示未来事件的记录:

http://pastebin.com/gwcv7qza

简而言之,基本问题是,有时我必须手动复制记录以使其显示在脚本中,并且我正在尝试找到解决方案 - 但我在寻找解决方案时遇到了麻烦。我自己试过了,还是不行。

我希望我已经解释得足够清楚了。

感谢任何有关解决此问题的帮助(只需在我的 pastebin 链接中发布解决方案,如果需要,您可以在其中向 pastebin 提交更正/修改。)

谢谢!

【问题讨论】:

    标签: php mysql arrays pagination recordset


    【解决方案1】:

    我认为问题出在您的 Paginatop 类中

    这一行 $result = ($page - 1) * $resultsPerPage + 1;将为第一页返回 1,您将显示 $this->items[$result] 数组中的第二个元素 - $this->items[1],而不是第一个 $this->items[0]。

    试试 $result = ($page - 1) * $resultsPerPage;

    对于第 1 页,$result 将为 0 第 2 页的 $result 将为 19(如果每页显示 20 条记录)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      相关资源
      最近更新 更多