简体   繁体   English

如何只选择前5个结果,然后显示更多..选项?

[英]How to select only first 5 results and then show more.. option?

How can i select the first 5 results and then add a see more option? 如何选择前5个结果,然后添加更多信息?

Below is the current code: 下面是当前代码:

  <?php

   $query="SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC";
   $result=mysql_query($query);

   $num=mysql_numrows($result);

    mysql_close();

    echo "";

     $i=0;
     while ($i < $num) {

  $otheris=mysql_result($result,$i,"sender_full_name"); 
  $sysid=mysql_result($result,$i,"sender_id");
   $dob=mysql_result($result,$i,"dob");

    // If $dob is empty
   if (empty($dob)) {

   $dob = "No new messages - 
   <a  id=missingdob href=/test.php?id=$uid>
   <bold>check later</bold></a>";
   }

   echo "<br><div id=linkcontain>
   <a id=otherlink href=$mem/profile.php?id=$uid>
    $manitis</a>
         <br><div id=dobpres>$dob</div></div>";

   echo "";

    $i++;
      }

       ?>

You should try to select 6 rows first time and if you get 6 records then show first 5 with a "show more option" 您应该尝试第一次选择6行,如果您获得6条记录,则使用“显示更多选项”显示前5条记录

"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 0, 6";

For subsequent times you should have your query like this: 对于随后的时间,您应该具有以下查询:

"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 6, 5";
"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 11, 5";
"SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 16, 5";
...
...

And every time "show more option" if you are able to fetch requested number of records. 并且每次“显示更多选项”是否能够获取请求的记录数。

$query="SELECT * FROM messages where u_id = '$uid' ORDER BY id DESC LIMIT 5"; 

http://dev.mysql.com/doc/refman/5.5/en/select.html http://dev.mysql.com/doc/refman/5.5/en/select.html

you could consider LIMIT 6 display only up to 5 if 6th exist display there is more options... 如果存在第6个显示,则可以考虑LIMIT 6最多显示5个显示...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM