AAA
AAA

Reputation: 3168

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 (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++;
      }

       ?>

Upvotes: 1

Views: 6078

Answers (3)

Pawan Deore
Pawan Deore

Reputation: 182

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(' ');
});}

Upvotes: 1

anubhava
anubhava

Reputation: 785196

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.

Upvotes: 2

bensiu
bensiu

Reputation: 25564

$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...

Upvotes: 1

Related Questions