<tfoot id='LJoFu'></tfoot>

<small id='LJoFu'></small><noframes id='LJoFu'>

  • <legend id='LJoFu'><style id='LJoFu'><dir id='LJoFu'><q id='LJoFu'></q></dir></style></legend>
    • <bdo id='LJoFu'></bdo><ul id='LJoFu'></ul>

      1. <i id='LJoFu'><tr id='LJoFu'><dt id='LJoFu'><q id='LJoFu'><span id='LJoFu'><b id='LJoFu'><form id='LJoFu'><ins id='LJoFu'></ins><ul id='LJoFu'></ul><sub id='LJoFu'></sub></form><legend id='LJoFu'></legend><bdo id='LJoFu'><pre id='LJoFu'><center id='LJoFu'></center></pre></bdo></b><th id='LJoFu'></th></span></q></dt></tr></i><div id='LJoFu'><tfoot id='LJoFu'></tfoot><dl id='LJoFu'><fieldset id='LJoFu'></fieldset></dl></div>
      2. 如何在不考虑 PDO 限制的情况下获取找到的总行数

        时间:2023-09-20
      3. <small id='XO78Q'></small><noframes id='XO78Q'>

          <tbody id='XO78Q'></tbody>
          <legend id='XO78Q'><style id='XO78Q'><dir id='XO78Q'><q id='XO78Q'></q></dir></style></legend>
              <bdo id='XO78Q'></bdo><ul id='XO78Q'></ul>
                <i id='XO78Q'><tr id='XO78Q'><dt id='XO78Q'><q id='XO78Q'><span id='XO78Q'><b id='XO78Q'><form id='XO78Q'><ins id='XO78Q'></ins><ul id='XO78Q'></ul><sub id='XO78Q'></sub></form><legend id='XO78Q'></legend><bdo id='XO78Q'><pre id='XO78Q'><center id='XO78Q'></center></pre></bdo></b><th id='XO78Q'></th></span></q></dt></tr></i><div id='XO78Q'><tfoot id='XO78Q'></tfoot><dl id='XO78Q'><fieldset id='XO78Q'></fieldset></dl></div>
                <tfoot id='XO78Q'></tfoot>

                • 本文介绍了如何在不考虑 PDO 限制的情况下获取找到的总行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我发现为了显示加载更多按钮而进行辅助查询以检查更多结果非常不专业.

                  我正在使用 PDO,有什么方法可以在没有限制过滤器的情况下获得找到的总行数,但仍然过滤结果?

                  当前代码:

                  //显示结果$开始= 0$r=$db->prepare("SELECT * FROM location WHERE area=:area LIMIT $start,10");$r->execute($fields);//查看是否有更多结果$r=$db->prepare("SELECT * FROM location WHERE area=:area");$r->execute($fields);$offset=$start+10;if($r->rowCount()>$offset){echo "

                  加载更多

                  ";}

                  解决方案

                  MySQL only AFAIK:

                  $r=$db->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM location WHERE area=:area LIMIT $start,10");$r->execute($fields);var_dump($r->fetchAll());var_dump($db->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN));

                  对于数据库服务器来说,当然与查询所有记录的时间一样繁重.对于非 MySQL 使用,此查询当然比获取所有记录的行数要好:

                  $r=$db->prepare("SELECT COUNT(*) FROM location WHERE area=:area");$r->execute($fields);$count = $r->fetch(PDO::FETCH_COLUMN);回声 $count;

                  I found it very unprofessional to make a secondary query to check for more results in order to display a load more button.

                  I'm using PDO, is there any way to get the total found rows without the limit filter but still filtering the results?

                  Current Code:

                  // Show Results
                  
                  $start = 0
                  
                  $r=$db->prepare("SELECT * FROM locations WHERE area=:area LIMIT $start,10");
                  $r->execute($fields);
                  
                  // See if there is more results
                  
                  $r=$db->prepare("SELECT * FROM locations WHERE area=:area");
                  $r->execute($fields);
                  
                  $offset=$start+10;
                  if($r->rowCount() > $offset){
                  echo "<div class='load'>Load More</div>";
                  }
                  

                  解决方案

                  MySQL only AFAIK:

                  $r=$db->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM locations WHERE area=:area LIMIT $start,10");
                  $r->execute($fields);
                  
                  var_dump($r->fetchAll());
                  
                  var_dump($db->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN));
                  

                  About as heavy for the database server as querying a single time for all the records of course. For non-MySQL use, this query is of course better then getting the rowcount of all the records:

                  $r=$db->prepare("SELECT COUNT(*) FROM locations WHERE area=:area");
                  $r->execute($fields);
                  $count = $r->fetch(PDO::FETCH_COLUMN);
                  echo $count;
                  

                  这篇关于如何在不考虑 PDO 限制的情况下获取找到的总行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 DEFAULT 值准备 MySQL INSERT/UPDATE 语句 下一篇:PDO MSSQL Server - 未找到驱动程序

                  相关文章

                  最新文章

                  <small id='z2eMW'></small><noframes id='z2eMW'>

                    <legend id='z2eMW'><style id='z2eMW'><dir id='z2eMW'><q id='z2eMW'></q></dir></style></legend>

                        <bdo id='z2eMW'></bdo><ul id='z2eMW'></ul>
                    1. <tfoot id='z2eMW'></tfoot>

                      <i id='z2eMW'><tr id='z2eMW'><dt id='z2eMW'><q id='z2eMW'><span id='z2eMW'><b id='z2eMW'><form id='z2eMW'><ins id='z2eMW'></ins><ul id='z2eMW'></ul><sub id='z2eMW'></sub></form><legend id='z2eMW'></legend><bdo id='z2eMW'><pre id='z2eMW'><center id='z2eMW'></center></pre></bdo></b><th id='z2eMW'></th></span></q></dt></tr></i><div id='z2eMW'><tfoot id='z2eMW'></tfoot><dl id='z2eMW'><fieldset id='z2eMW'></fieldset></dl></div>