Not able to create facebook like timeline

i’m trying to print posts just like facebook timeline with infinite scroll jquery and php, mysql. i wrote a join mysql query to fetch posts from groups and updates. The problem is i’m plagued by duplicate posts and unable to separate the group posts from updates in raw data. i tried a couple of times to sepearate and place them in jumbotron classes but i fail. Though the code is lengthy i hope to find some corrections and answers by sharing it. i need to prevent duplicate posts coming up through the query and printing while the ajax request go through’s too.

php class query:

public function totalUpdates($friend,$session,$var_id, $load) {
    try{
    $sql2="select distinct g.*,u.avatar,u.user_id,up.* from group_posts as g "
            . " join user as u on uname=g.author_gp "
            . " join updates as up on u.uname=up.author"
            . " where g.gname='MEP news' and (up.update_id >:update_id_all or g.gp_id>:update_id_all) and up.author in(:friend, :session) order by time,pdate desc limit $load,5
";

//$sql2="SELECT distinct update_id,update_body,time,title,user_id_u,account_name,author,data FROM updates where author in(:friend,:session)  and update_id not in(:update_id_all)  order by time desc limit $load,5";
        $stmth=  $this->_db->prepare($sql2);//Check here syntax of $db 
    
    $stmth->bindValue(":friend",$friend);
    $stmth->bindValue(":session",$session);
    $stmth->bindValue(":update_id_all",$var_id);
    //$stmth->bindValue(":update_id2",$update_id2);
    $stmth->execute();
    return $stmth->fetchAll();
    } catch (PDOException $ei){
        echo $ei->getMessage();
    }
}

PHP script that prints values:


$totalUpdates=$project->totalUpdates($id,$_SESSION['uname'] ,$im,$load);   

 
    /*

     *we get the $sess_count and $load from javascript in home page and forward the logic if load*2 is greater than 
     * $sess_count variable if it is great then the $total_sess_count is set to 0 else it is fetched from classes.inc.php 
     *     
     */
    
    if($load*5<$sess_count){
        $total_sess_count=0;
    }
 else {
    
  $total_sess_count=$project->totalupdatescount($id);
 }


   foreach ($totalUpdates as $j=>$row1) {
 echo '<pre>';
 print_r($row1);
 echo '</pre>';
 if(isset($row1['update_id'])){
       $updateid=$row1['update_id'];
                
                $account_name=$row1['account_name'];
                $u_id=$row1['user_id_u'];
                $author=$row1['author'];
                $post_date=$row1['time'];
                $title= stripslashes($row1['title']);
                $data= stripslashes($row1['update_body']);
              $data1=  hashtags($data);
              //$data1=  taggingsys($data0);
              $pic=$project->viewByUname($author);
              $uid=$pic['user_id'];
         $datemade = strftime("%B %d, %y", strtotime($post_date));
      $avatar=$pic['avatar'];
$statusui_edit="<b class='i-select'><i class='no' style='display:none;' no='".($updateid?$updateid:$postid)."'>".($updateid?$updateid:$postid).",</i> <div type='".($updateid?$updateid:$postid)."' class='hide hidden_edit_4_session session_editor".($updateid?$updateid:$postid)." jumbotron'>"
            . "<a type='".$updateid."' class='btn pull-right close_edit' title='Close without editing'>Close X</a>"
            . "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >"
            . "<span>&nbsp;</span>"
            . "<textarea id='wall_edit_".$updateid."' type='".$updateid."' rows='5' cols='50'  class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$_SESSION['uname']."'>
             ".html_entity_decode($data1)."</textarea><br>"
            . "<span class='pull-left spinner_edit".$updateid."'></span><button style='float:right;' value='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div></b>" ;
 }
 elseif (isset ($row1['gp_id'])) {
              
         
      $postid=$row1['gp_id'];
        $post_auth=$row1['author_gp'];
        $post_type=$row1['type'];
        $post_title=  html_entity_decode($row1['title']);
        $post_data=  html_entity_decode($row1['data']);
        $data0=  hashtags($post_data);
              $data1=  taggingsys($data0);
        $post_date=$row1['pdate'];
        $post_avatar=$row1['avatar'];
        $post_uid=$row1['user_id'];
 
               $edit="<div type='".$postid."' class='hidden_edit_g_description PB_G_".$postid." jumbotron'><span  id='spinner".$postid."'></span>"
            . "<a type='".$postid."' class='btn pull-right close_edit' title='Close without editing'>Close X</a>"
            . "<span>&nbsp;</span>"
        . "<input type='text' class='form-control title_g_edit title_g_".$postid."' name='g_status_title' value='".html_entity_decode($post_title)."' placeholder='Title' >"
            . "<textarea id='wall_edit_".$postid."' type='".$postid."' rows='5' cols='50'  class='session_edit text_value_".$postid."' wrap='hard' placeholder='update your description'>
             ".$post_data."</textarea><br>"
. "<span class='group_spinner'></span><button style='float:right;' value='".$postid."' type='edit_desc1' class='btn btn-warning btn btn-large btn-lg post-status-edit'>Update</button></div>" ;
}

Jquery script:

var load=0; 
     var sess_uname="<?php echo $session_uname;?>";
     var f_uname="<?php echo htmlspecialchars($_GET['u']);?>";
     var sess_count="<?php echo $total_sess_count;?>";
     var f_count="<?php echo $total_friend_count;?>";
    var funame="<?php echo $f_uname0;?>";
$(".message").html("<div style='display: flex; justify-content: center;'><h1>Loading Posts...</h1> &nbsp;  "+spinner1+"</div>").show();
   
    if(sess_uname==f_uname){
        
        $(window).scroll(function(){
       
       //alert($(window).scrollTop()); 
          // alert($(window).scrollTop()+" "+$(document).height()-$(window).height());
             if($(window).scrollTop()==$(document).height()-$(window).height()){
                 var sub=$(document).height()-$(window).height();
      //lert(sub);
           // alert($(window).scrollTop()+"  "+sub); 
            load++;      
            var ids1=[];
             var ids=$(".i-select i").text();
           ids1.push(ids);
            //var arr=$(ids).serializeArray();
         var arrJSON=JSON.stringify( ids1);  
        var strids=ids.toString();
       var newids = strids.split(",");
      
        var len=newids.length;
       // alert(newids);
          //  for(x=0;x<len;x++){
         // alert('ids:- ' + newids[x] +" len:-  "+ len);
         var newid1=newids[load];
    // alert(newids[x]);
   var first=$(".i-select i:first").text();      
   var last= $("i:last").text();
    //console.log(first+"--1---2-- "+last);     

                // alert(load+" "+sess_count);
             if(load * 5< sess_count){
                 $(".message").html("<h1>no more posts to show </h1>");
             }  else{
                 $.post("st&com.php", {"load":load,"sess_count":sess_count,"update_id2":last,"update_id1":arrJSON},function(data){
        $(".message").html(spinner1).show();         
        $("#status_area").append(data);
                    $(".hide").hide();
        $(".message").html(spinner1).hide();            
  
    }); }
             }
         });
     }else {
         $(window).scroll(function(){
           
             if($(window).scrollTop()==$(document).height()-$(window).height()){
             load++;
   // alert($(window).scrollTop()+"  "+$(document).height()-$(window).height());
             if(load *2 >f_count){
                 $(".message").html("<h1>no more posts to show here</h1>");
             }else{
                
                 $.post("status_list.php", {funame:funame, load:load},function(data){
        $(".message").html(spinner1).show();         
        $("#status_area").append(data);
                    $(".hide").hide();
        $(".message").html(spinner1).hide();            
        
                 });
             }
             }
         });    
     }

sample output:


Array
(
    [gp_id] => 103
    [0] => 103
    [pid] => 0
    [1] => 0
    [gname] => MEP news
    [2] => MEP news
    [author_gp] => aboutthecreator
    [3] => aboutthecreator
    [type] => a
    [4] => 0
    [title] => qwertyu
    [5] => 2
    [data] => 
    [6] => <div>Etiam iaculis nunc ac metus. Praesent egestas tristique nibh.</div>
<div>&nbsp;</div>
<div>Fusce ac felis sit amet ligula !qwerty pharetra condimentum. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris.</div>
<div>&nbsp;</div>
<div>Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien !bart, a accumsan nisi mauris ac eros. Sed in libero ut nibh placerat accumsan.</div>
<div>&nbsp;</div>
<div>Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Sed a libero. !qwerty</div>
    [pdate] => 2019-12-19 22:28:04
    [7] => 2019-12-19 22:28:04
    [vote_up] => 0
    [8] => 0
    [vote_down] => 0
    [9] => 0
    [group_id] => 25
    [10] => 25
    [author_id] => 142
    [11] => 142
    [avatar] => ThuJul1821235420191075.jpg
    [12] => ThuJul1821235420191075.jpg
    [user_id] => 142
    [13] => 142
    [update_id] => 381
    [14] => 381
    [update_body] => Lorem ipsum dolor sit amet,consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Lorem ipsum dolor sit amet, <a href="home.php?u=shan2batman">@shan2batman</a><br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam voluptua. !qwerty Lorem ipsum dolor sit amet, consetetur sadipscing elitr, Lorem ipsum dolor sit amet, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, consetetur sadipscing elitr, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. no sea takimata sanctus est Lorem ipsum dolor sit amet. <br /><br />Lorem ipsum dolor sit amet,sed diam voluptua. Lorem ipsum dolor sit amet, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, consetetur sadipscing elitr, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam voluptua. Stet clita kasd gubergren, Lorem ipsum dolor sit amet, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, <br /><br />Lorem ipsum dolor sit amet,At vero eos et accusam et justo duo dolores et ea rebum. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, sed diam voluptua. Stet clita kasd gubergren, <br /><br />
    [15] => Lorem ipsum dolor sit amet,consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Lorem ipsum dolor sit amet, <a href="home.php?u=shan2batman">@shan2batman</a><br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam voluptua. !qwerty Lorem ipsum dolor sit amet, consetetur sadipscing elitr, Lorem ipsum dolor sit amet, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, consetetur sadipscing elitr, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. no sea takimata sanctus est Lorem ipsum dolor sit amet. <br /><br />Lorem ipsum dolor sit amet,sed diam voluptua. Lorem ipsum dolor sit amet, sed diam voluptua. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, Stet clita kasd gubergren, <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. sed diam voluptua. <br /><br />Lorem ipsum dolor sit amet,consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam voluptua. consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, At vero eos et accusam et justo duo dolores et ea rebum. At vero eos et accusam et justo duo dolores et ea rebum. no sea takimata sanctus est Lorem ipsum dolor sit amet. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, consetetur sadipscing elitr, <br /><br />Lorem ipsum dolor sit amet,Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam voluptua. Stet clita kasd gubergren, Lorem ipsum dolor sit amet, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, <br /><br />Lorem ipsum dolor sit amet,At vero eos et accusam et justo duo dolores et ea rebum. sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, At vero eos et accusam et justo duo dolores et ea rebum. consetetur sadipscing elitr, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, sed diam voluptua. Stet clita kasd gubergren, <br /><br />
    [url] => 
    [16] => 
    [time] => 2018-11-10 22:58:36
    [17] => 2018-11-10 22:58:36
    [host] => 
    [18] => 
    [19] => 0
    [20] => 0
    [21] => qwertyu
    [user_id_u] => 142
    [22] => 142
    [account_name] => aboutthecreator
    [23] => aboutthecreator
    [author] => aboutthecreator
    [24] => aboutthecreator
    [25] => a
    [26] => 
)

I don’t think this is correct:

. " where g.gname='MEP news' and (up.update_id >:update_id_all or g.gp_id>:update_id_all) and up.author in(:friend, :session) order by time,pdate desc limit $load,5"

                                                       ^                        ^

and then

$stmth->bindValue(":update_id_all",$var_id);

You can’t stick the same value in two parameters using one call. I don’t think you can have two parameters with the same name in a prepared statement.

@droopsnoot i still face the same problem even after your suggestion.