Jump to content

how to make infinity scroll work as the code i worked is not working?


Go to solution Solved by shan2batman,

Recommended Posts

Guys i'm trying to create a infinite scroll feature for a project of mine and i couldn't make it work in the infinite scroll fashion any inputs would be appreciated.

 

Jquery code:

$(document).ready(function(){
        var load=0;

     var sess_uname="<?php echo $session_uname;?>";
     var f_uname="<?php echo $f_uname;?>";
     var sess_count="<?php echo $total_sess_count;?>";
     var f_count="<?php echo $total_friend_count;?>";
     if(sess_uname==f_uname){
         $(window).scroll(function(){
             if($(window).scrollTop()==$(document).height()-$(window).height()){
             load++;
             alert('hai1');
             if(load *5 >sess_count){
                 $(".message").text("no more posts to show");
             }else{
                 $.post("st&com.php", {load:load},function(data){
                    // $(".status_area").append(data);
                    alert('hai');
                 });
             }
             }
         });
     }   
    });

here is the php code:


$load= (int)($_POST['load'])*2;
$sess_id=(int)$_SESSION['id'];
$friends = array();
$stmt= $conn->prepare("select friend_one, friend_two from friends where (friend_one=:session OR friend_two=:session) and accepted='1'");
$stmt->bindparam(":session",$_SESSION['uname']);
$stmt->execute();
$fetch=$stmt->fetchAll();
$count=count($fetch);
if($count==0){
$totalids=$project->totalUpdates1($sess_id,$load);

here is the class:

public function totalUpdates1($id, $load) {
    $sql2="SELECT * FROM updates WHERE user_id_u=:id order by time desc limit $load,5";
    $stmth=  $this->_db->prepare($sql2);//Check here syntax of $db 
    $stmth->bindValue(":id",$id);
    //$stmth->bindValue(":load",$load);
    $stmth->execute();
    return $stmth->fetchAll();
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.