开发者

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?

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 (em开发者_开发知识库pty($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"

"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

you could consider LIMIT 6 display only up to 5 if 6th exist display there is more options...


window.onload = function(){

$(".box").hide();
$(".box").slice(0, 5).show(); // select the first ten
$("#load").click(function(e){ // click event for load more
    e.preventDefault();
    $("div:hidden").slice(0, -1).show(); // select next hidden divs and show them
    $("#load-more-div").html(' ');
});}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜