<legend id='ivHQy'><style id='ivHQy'><dir id='ivHQy'><q id='ivHQy'></q></dir></style></legend>
  • <small id='ivHQy'></small><noframes id='ivHQy'>

      <tfoot id='ivHQy'></tfoot>

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

        <bdo id='ivHQy'></bdo><ul id='ivHQy'></ul>

      1. php中的分页

        pagination in php(php中的分页)
            <tbody id='iL6gt'></tbody>
            <bdo id='iL6gt'></bdo><ul id='iL6gt'></ul>
              <i id='iL6gt'><tr id='iL6gt'><dt id='iL6gt'><q id='iL6gt'><span id='iL6gt'><b id='iL6gt'><form id='iL6gt'><ins id='iL6gt'></ins><ul id='iL6gt'></ul><sub id='iL6gt'></sub></form><legend id='iL6gt'></legend><bdo id='iL6gt'><pre id='iL6gt'><center id='iL6gt'></center></pre></bdo></b><th id='iL6gt'></th></span></q></dt></tr></i><div id='iL6gt'><tfoot id='iL6gt'></tfoot><dl id='iL6gt'><fieldset id='iL6gt'></fieldset></dl></div>
              <tfoot id='iL6gt'></tfoot>
            1. <legend id='iL6gt'><style id='iL6gt'><dir id='iL6gt'><q id='iL6gt'></q></dir></style></legend>

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

                • 本文介绍了php中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用它来收集特定用户的评论.我想在每页上显示 7 条评论并希望启用分页.实施步骤是什么.对不起.n00b 问题.

                  i am using this to collect comments made abt a particular user. i want to display 7 comments on each page and want to enable pagination. what would be the steps of implementation. sorry. n00b question.

                  $query = "SELECT msg, user_id, comment_time FROM comments WHERE aid = '$aid' ORDER BY comment_time DESC";
                          $result = mysql_query($query) or die("ERROR: $query.".mysql_error());
                          if (mysql_num_rows($result) > 0) {
                              while($row = mysql_fetch_object($result)){
                                  $uidval = $row->user_id;
                                  if ($uidval != 0){
                                  $userInfo = $facebook->api_client->fql_query("SELECT name, pic_square_with_logo, profile_url FROM user WHERE uid='".$uidval."'");
                  
                              //  echo '<br>Array Info<br>';
                              //  print_r($userInfo);
                              //  echo '<br><br>';
                  
                                  $nameuser = $userInfo[0]['name'];
                                  $pic = $userInfo[0]['pic_square_with_logo'];
                                  $profile_url = $userInfo[0]['profile_url'];
                  
                                  echo '<img src="'.$pic.'" />';
                                  echo '<a href="'.$profile_url.'">'.$nameuser.'</a>';
                                  echo '<br>';
                                  echo $row->comment_time;
                                  echo '<br>';
                                  echo $row->msg;
                                  echo '<br>';
                                  }
                  
                              }
                          }
                  

                  推荐答案

                  该解决方案最好通过 SQL 的限制/偏移子句实现.对于 MySQL,这是通过将 LIMIT [offset] [count] 附加到您的查询来实现的.PostgreSQL 使用单独的 select ... LIMIT [count] OFFSET [offset] 语法.

                  The solution is best achieved via SQL's limit/offset clauses. For MySQL, this is achieved via appending LIMIT [offset] [count] to your query. PostgreSQL uses separate select ... LIMIT [count] OFFSET [offset] syntax.

                  这个想法是您将返回的结果数量限制为您想要显示的实际数量.如果您显示 200 页中的第 1 页,每页有 100 个结果,它可以显着提高性能.

                  The idea is you limit the number of results returned to the actual number you want to display. It can yield a huge performance increase if you're displaying page 1 of 200, with a hundred results per page.

                  当然,您需要运行第二个查询 - 一个 select count(*) from ... 以确定结果集中的结果数.将其除以每页的结果数,您就得到了页数.

                  Of course, you need to run a second query - a select count(*) from ... to determine the number of results in the result set. Divide this by the number of results per page, and you've got the number of pages.

                  您可能希望在查询字符串中传递一个页面参数,例如

                  You will likely want to pass a page parameter in the query string, something like

                  http://mysite.com/index.php?page=7
                  

                  然后使用类似的方法提取数据(考虑这个伪代码;我知道我实际上没有正确查询)

                  and then pull the data using a similar method (consider this pseudo code; I know I'm not actually querying properly)

                  <?php
                  
                  $num_per_page = 20; // 20 results per page
                  
                  $page = isset($_GET['page']) ? $_GET['page'] : 0; // start from page 0
                  
                  // Build our big query minus the SELECT part here
                  $from_part = 'tbl_results [where ...]"'
                  
                  $num_results = query("SELECT COUNT(*) FROM $from_part");
                  
                  // Use ceil to round upwards
                  $num_pages = ceil($num_results / $num_per_page);
                  
                  // Cap the page a the last page
                  if ($page > $num_pages)
                    $page = $num_pages;
                  
                  // Cap the page at the first page
                  if ($page <= 1)
                    $page = 1;
                  
                  $offset = $page * $num_per_page;
                  
                  // Build the final query to select the relevant page of data
                  $results = query("SELECT * FROM $from_part LIMIT $offset, $num_per_page");
                  
                  ?>
                  

                  这篇关于php中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

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

                        <bdo id='8AmXl'></bdo><ul id='8AmXl'></ul>

                        1. <small id='8AmXl'></small><noframes id='8AmXl'>

                            <tfoot id='8AmXl'></tfoot>
                              <tbody id='8AmXl'></tbody>