
narutofan
Members-
Posts
64 -
Joined
-
Last visited
Everything posted by narutofan
-
not able to create a facebook like timeline
narutofan replied to narutofan's topic in PHP Coding Help
@Psycho don't get agitated on me for my poor words(its not my native tongue pl bear with me). i stated the problem clearly i couldn't separate update table results with group_post table results from the join query i tried to separate them using isset() in a if condition but i fail, to make things easier i even posted a sample output from the query. since i couldn't comeup with an answer i came here to get your and others expert opinion and by the learning way i would remove duplicate results too. -
not able to create a facebook like timeline
narutofan replied to narutofan's topic in PHP Coding Help
@Psycho thanks but your mysql suggestion didn't bring up a single post. i'm sorry for making it lengthy some ppl in the forum expect full code instead of shortened one's thats why i posted it so lengthy sorry again if it irritated or made you angry. -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand i found out what the problem was update_id1 had an array like this array ([0]=>398,399,405,407) so it was not incrementing hence the problem. but now i face a new problem that is based on the same scripts above you can check it in this link if you think you can spare some time in your busy schedule pl check it out. -
i'm trying to print posts just like facebook timeline with infinite scroll jquery and php, mysql. i wrote a inner 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: $f = array(); $ids= array(); $stmt= $conn->prepare("select friend_one, friend_two from friends where (friend_one=:session OR friend_two=:session) and (friend_one>=:session or friend_two>=:session) and accepted='1'"); $stmt->bindparam(":session",$_SESSION['uname']); $stmt->execute(); $f=$stmt->fetchAll(); $f_count=count($f); $ids= ff($f, $project); //$k=0; //for ($k=0;$k<count($ids);$k++){ //while($i<$f_count){ //$id=$v; //$i=0; //foreach ($update_id1 as $i => $v) { $ex= explode(",", $update_id1[0]); $unique=array_unique($ex); $im= implode(",", $unique); //fetch username from update table in db and inject it to the feed query. $imp_id="'" .join( "','", $ids)."'"; $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']; if ($avatar!=""){ $feed_pic='../user/user/'.($uid?$uid:$post_avatar).'/'.$avatar; } else { $feed_pic='img/avatardefault.png'; } $words=explode(" ", ($data1?$data1:$data2)); $count_words=count($words); if($count_words>180){ $partial_data1= join(" ", array_slice($words,0,150)); $more="<button class='btn btn-link more' data-id='".$updateid."'>...More</button>"; }else{ $partial_data1=($data1?$data1:$data2); $more=""; } $vote_up_count=$project->voteUpdateCheck($updateid, $_SESSION['id']); if($vote_up_count[0][0]>0){ $vote_like=TRUE; } else { $vote_like=FALSE; } if($vote_up_count[0][1]>0){ $vote_dislike=TRUE; } else { $vote_dislike=FALSE; } include 'ratings/vote_count.php'; if ( $vote_like==TRUE && $vote_dislike==FALSE) { $like='<a type="liked" class="btn btn-warning liked status_like_'.$updateid.' " attr="'.$updateid.'">Liked</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$updateid.' " attr="'.$updateid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } elseif ($vote_dislike==TRUE && $vote_like==FALSE) { $like='<a type="like" class="btn btn-warning status_like_'.$updateid.' like" attr="'.$updateid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="disliked" class="btn btn-danger disliked status_unlike_'.$updateid.'" attr="'.$updateid.'">Disliked</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } else { $like='<a type="like" class="btn btn-warning status_like_'.$updateid.' like" attr="'.$updateid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$updateid.' unlike" attr="'.$updateid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } $share_button=""; $hidden_text= '<textarea class="hidden_textarea hidden_value'.$updateid.'" disabled>'.$data.'</textarea>'; $share_button="<a class='btn btn-primary share_btn share_".$updateid."' title='".$title."' type='share' id='".$updateid."'>Copy</a>"; $reply_btn=""; if ($author==$_SESSION['uname'] || $account_name==$_SESSION['uname']) { $statusdeletebutton='<li>' . '<a type="'.$updateid.'" class="btn delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_status_btn" title="Delete this status and its replies">Remove</a></li>'; $edit_btn='<li>' . '<a attr="'.$updateid.'" type="'.$updateid.'" class="btn edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'; $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> </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>" ; }else{ $statusdeletebutton=""; $edit_btn="<li class='posted'>You are not the owner of this Post</li>"; $statusui_edit=""; $report_btn='<li><a href="#'.$updateid.'" attr="'.$_SESSION['id'].'" account-name="'.$author.'" type="'.$updateid.'" id="'.$f_uid.'" class="report_offence glyphicon glyphicon-warning-sign" title="Edit this status" >Report</a></li>'; } echo $statusui_edit.''. $hidden_text.'' . '<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes border border-warning status_'.$updateid.' jumbotron">' . '<h3 class="pull-left title">' . '<div id="#'.$updateid.'" attr="'.$updateid.'" class="title_s_2copy posted" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>' . '<span class="pull-right">' . '<div class="dropdown">' . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" >' . '<span class="glyphicon glyphicon-edit"></span></button>' . '<ul class="dropdown-menu">' .$edit_btn .' '. $statusdeletebutton .''.$report_btn.'</ul></div></span><br><hr>' . '<legend><span style="font-size: 13.5px;" class=" data_s_2copy" type="'.$updateid.'" >' . '<div class="descrip" data-id="'.$updateid.'">' . html_entity_decode($partial_data1)." <br>".$more.'</div></span></legend><b class="posted"><small>Posted by:- <a href="home.php?u='.$author.'"><img src="'.$feed_pic.'" height="20px" width="20px"> '.$author. '</a> on '.$datemade.'</b>' . '<br><span class="pull-left spinner_status'.$updateid.'"></span><legend>'.$like.' | '.$unlike. ' | '.$share_button.'</legend></small><span class="edit-spinner"></span>'; ?> <h4><a id="<?php echo $updateid;?>" class="btn btn-default collap-btn">Comments</a></h4> <!-- Collapsible Element HTML --> <div id="toggle<?php echo $updateid;?>" class="collapse scroll-comments"> <?php // Fetch Comments of update $totalComments=$project->totalComments($_SESSION['uname'],$friend,$updateid); foreach($totalComments as $row1){ $status_reply_id=$row1['comment_id']; $reply_d=htmlentities($row1['comment_body']); $reply_data= stripslashes($reply_d); $reply_osid=$row1['os_id']; $reply_date=$row1['time_c']; $reply_author=$row1['author_c']; $reply_data1= hashtags($reply_data); //$reply_data1= taggingsys($reply_data0); //$reply_data1= taggingsys($reply_data0); $datemade_r = strftime("%B %d, %y", strtotime($reply_date)); include 'ratings/vote_count4comments.php'; $vote_up_count_r=$project->voteReplyCheck($_SESSION['id'], $status_reply_id); if($vote_up_count_r[0][0]>0){ $vote_like_r=TRUE; } else { $vote_like_r=FALSE; } if($vote_up_count_r[0][1]>0){ $vote_dislike_r=TRUE; } else { $vote_dislike_r=FALSE; } if ( $vote_like_r==TRUE && $vote_dislike_r==FALSE) { $like_r='<a type="liked" class="btn btn-warning status_liker_'.$status_reply_id.' liked_r" attr="'.$status_reply_id.'">Liked</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unliker_'.$status_reply_id.' unlike_r" attr="'.$status_reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } elseif ($vote_dislike_r==TRUE && $vote_like_r==FALSE) { $like_r='<a type="like" class="btn btn-warning status_liker_'.$status_reply_id.' like_r" attr="'.$status_reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unliked" class="btn btn-danger status_unliker_'.$status_reply_id.' disliked_r" attr="'.$status_reply_id.'">Disliked</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } else { $like_r='<a type="like" class="btn btn-warning status_liker_'.$status_reply_id.' like_r" attr="'.$status_reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unliker_'.$status_reply_id.' unlike_r" attr="'.$status_reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } $pic=$project->viewByUname($reply_author); $uid=$pic['user_id']; $avatar=$pic['avatar']; if ($avatar!=""){ $feed_r_pic='../user/user/'.$uid.'/'.$avatar; } else { $feed_r_pic='img/avatardefault.png'; } if ($reply_author==$_SESSION['uname'] ) { $reply_delete_button='<li><a type="'.$status_reply_id.'" class="btn delete_reply_btn glyphicon glyphicon-trash delete_reply_"'.$status_reply_id.'" title="Delete this comment"> Remove</a></span></li>'; } else{ $reply_delete_button=""; } echo ' <div class="replyboxes pull-left reply_' .$status_reply_id.'">' . 'Reply by:- ' . '<a href="home.php?u='.$reply_author. '"><img src="'.$feed_r_pic.'" height="20px" width="20px"> '.$reply_author.'</a>' . '<span class="pull-right">'.$datemade_r . '<b class="dropdown"> <small><span class="btn btn-xs btn-danger dropdown-toggle pull-right" data-toggle="dropdown" > <span class="glyphicon glyphicon-edit"></span></span> <ul class="dropdown-menu">'.$reply_delete_button . '<li><a class="glyphicon glyphicon-warning-sign" href="report.php?u='.$reply_author.'"> Report</a><li></ul></span>' . '</small></b><br><legend>'. html_entity_decode($reply_data1).'<br><span class="pull-left spinner_comment'.$status_reply_id.'"></span>'.$like_r.'|'.$unlike_r.'</legend></div>'; } echo '<textarea id="reply_textarea_'.$updateid.'" update-detail="'.$updateid.'" class="atwho-inputor status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>' . '<span class="pull-left spinner_comment_post'.$updateid.'"></span><button id="reply_butn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_butn reply_'.$updateid.'">Reply</button><span id="status_spinner_r"></span></div></div>'; } /* * group variables * */ 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']; if ($post_avatar != ""){ $g_pic='../user/user/'.$post_uid.'/'.$post_avatar; } else { $g_pic='img/avatardefault.png'; } if ($post_auth==$_SESSION['uname']) { $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> </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>" ; $edit_btn= '<li><a attr="'.$postid.'" type="edit_desc1" class="btn edit_g_description hidden_text_edit glyphicon glyphicon-pencil" title="Edit this description" >Edit</a></li>'; $statusdeletebutton='<li><a type="'.$postid.'" class="btn delete_4_session hidden_text_delete_'.$postid.' glyphicon glyphicon-trash delete_status_btn" title="Delete this status and its replies">Remove</a></li>'; $report_btn=""; } else { $edit=""; $edit_btn="You are not the owner of this post"; $statusdeletebutton=""; $report_btn="<li><a href='#".$postid."' postid=".$postid." reporter-uid=".$_SESSION['id']." reporter-name=".$_SESSION['uname']." offender=".$post_auth." class='report glyphicon glyphicon-warning-sign '>Report</a></li>"; } $user_image="<img src='{$g_pic}' alt='{$post_auth}' title='{$post_auth}' width='30' height='30'>"; $words=explode(" ", $data1); $count_words=count($words); if($count_words>180){ $partial_data1= join(" ", array_slice($words,0,150)); $more="<button class='btn btn-link more' data-id='".$postid."'>...More</button>"; }else{ $partial_data1=$data1; $more=""; } $vote_up_count=$project->voteGroupCheck($postid, $_SESSION['id']); if($vote_up_count[0][0]>0){ $vote_like=TRUE; } else { $vote_like=FALSE; } if($vote_up_count[0][1]>0){ $vote_dislike=TRUE; } else { $vote_dislike=FALSE; } include 'ratings/vote_count_g.php'; if ( $vote_like==TRUE && $vote_dislike==FALSE) { $like='<a type="liked" class="btn btn-warning liked status_like_'.$postid.' liked" attr="'.$postid.'">Liked</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$postid.' unlike" attr="'.$postid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } elseif ($vote_dislike==TRUE && $vote_like==FALSE) { $like='<a type="like" class="btn btn-warning status_like_'.$postid.' like" attr="'.$postid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="disliked" class="btn disliked btn-danger status_unlike_'.$postid.'" attr="'.$postid.'">Disliked</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } else { $like='<a type="like" class="btn btn-warning status_like_'.$postid.' like" attr="'.$postid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$postid.' unlike" attr="'.$postid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } #build threads. echo $edit."<div id='PB_".$postid."' value='".$postid."' class='jumbotron'><span id='spinner".$postid."'></span>" . "<legend>{$post_title}" . "<span class='pull-right'>" . "<div class='dropdown'>" . "<button type='button' class='btn btn-danger dropdown-toggle' data-toggle='dropdown' >" . "<span class='glyphicon glyphicon-edit'></span></button>" . "<ul class='dropdown-menu'>" .$edit_btn ." ". $statusdeletebutton ." ".$report_btn. "</ul></div></span><br></legend>" . '<div class="descrip" data-id="'.$postid.'">' . "<legend>{$partial_data1}<br>{$more}<br></div><span class='spinner_g_u{$postid}'></span>{$like} | {$unlike} <br>Posted by:<a href='home.php?u={$post_auth}&v={$_SESSION['uname']}'>{$user_image} {$post_auth}</a>-- {$post_date}<hr><br></legend> <h4><a id='{$postid}' class='btn btn-default collap-btn'>Comments</a></h4><div class='collapse scroll-comments' id='toggle{$postid}'>"; #get replies and user image using inner loop $num_rows1=$project->groupcount_replies($postid); $fetch1=$project->group_replies($postid); if ($num_rows1>0) { foreach ($fetch1 as $row1) { $reply_id=$row1['gp_id']; $reply_pid=$row1['pid']; $reply_auth=$row1['author_gp']; $reply_data=$row1['data']; $data11= hashtags($reply_data); $data12= taggingsys($data11); $reply_date=$row1['pdate']; $reply_avatar=$row1['avatar']; $reply_uid=$row1['user_id']; if ($reply_avatar != ""){ $r_pic='../user/user/'.$reply_uid.'/'.$reply_avatar; } else { $r_pic='img/avatardefault.png'; } /* include 'ratings/vote_count_g4comments.php'; $like_r='<a type="like" class="btn status_liker_'.$reply_id.' like_r" attr="'.$reply_id.'">Like</a>('.$num_likes_r[0].')'; $unlike_r='<a type="unlike" class="btn status_unliker_'.$reply_id.' unlike_r" attr="'.$reply_id.'">Dislike</a>('.$num_unlikes_r[0].')'; */ $vote_up_count_r=$project->voteGroupReplyCheck($_SESSION['id'],$reply_id); if($vote_up_count_r[0][0]>0){ $vote_like=TRUE; } else { $vote_like=FALSE; } if($vote_up_count_r[0][1]>0){ $vote_dislike=TRUE; } else { $vote_dislike=FALSE; } include 'ratings/vote_count_g4comments.php'; if ( $vote_like==TRUE && $vote_dislike==FALSE) { $like_r='<a type="liked" class="btn btn-warning status_like_'.$reply_id.' liked_r" attr="'.$reply_id.'">Liked</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unlike_'.$reply_id.' unlike_r" attr="'.$reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } elseif ($vote_dislike==TRUE && $vote_like==FALSE) { $like_r='<a type="like" class="btn btn-warning status_like_'.$reply_id.' like_r" attr="'.$reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unliked" class="btn btn-danger disliked_r status_unlike_'.$reply_id.'" attr="'.$reply_id.'">Disliked</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } else { $like_r='<a type="like" class="btn btn-warning status_like_'.$reply_id.' like_r" attr="'.$reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unlike_'.$reply_id.' unlike_r" attr="'.$reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } $reply_img="<img src='{$r_pic}' alt='{$reply_auth}' title='{$reply_auth}' width='15' height='15'>"; #build replies echo "<div id='reply_body'>" . "<small>Posted by:<a href='home.php?u={$reply_auth}&v={$_SESSION['uname']}'>{$reply_img} {$reply_auth}</a>-- {$reply_date}</small><br>" . "<legend>{$data12}<br><span class='spinner_g_r{$reply_id}'></span>{$like_r} | {$unlike_r} </legend></div>"; } } echo '<br>' . '<textarea id="reply_textarea_'.$postid.'" update-detail="'.$postid.'" class="group_reply1 input-custom2" placeholder="comment\'s"></textarea>' . '<br><span class="group_reply"></span><button group-id="'.$_SESSION['g_id'].'" user-id="'.$_SESSION['id'].'" action="post_reply" id="'.$postid.'" attr="'.$postid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply">Reply</button><br></div></div>'; } break; } 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> "+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> </div> <div>Fusce ac felis sit amet ligula !qwerty pharetra condimentum. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris.</div> <div> </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> </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] => )
-
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand are you there bro show me a sign -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barandi'm not a mysql or a javascript guy i can't imagine how to write efficient queries.i have asked too much of you it seems. i'll post the data being passed here its html i get the first two posts from mysql table but after that it isn't showing anything i suspect that the $friend variable and $unique variable is not working properly, firebug in chrome doesnt show any errors just wait for the html data being produced by the ajax and query. here is the output from the page: <div id="status_area"> <div class="message" style="display: none;"><span class="fa fa-gear fa-spin" style="width: 5rem; height: 5rem;"></span></div> update_id1:- ids:- 0<br><b class="i-select"><i class="no" style="display:none;" no="398">398,</i> <div type="398" class="hide hidden_edit_4_session session_editor398 jumbotron" style="display: none;"><a type="398" class="btn pull-right close_edit" title="Close without editing">Close X</a><input type="text" class="form-control title_s_edit title_s_398" name="status_title" value=" 123456" placeholder="Title"><span> </span><textarea id="wall_edit_398" type="398" rows="5" cols="50" class="session_edit text_value_398" wrap="hard" placeholder="whats up aboutthecreator"> <div>Vivamus elementum semper <a class="btn btn-link" href="hash_sys.php?tag=qwerty"> !qwerty </a> nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Praesent ac massa at ligula laoreet iaculis.</div></textarea><br><span class="pull-left spinner_edit398"></span><button style="float:right;" value="398" type="a" class="btn btn-warning btn btn-large btn-lg post-s-edit">Update</button></div></b><textarea class="hidden_textarea hidden_value398" disabled=""><div>Vivamus elementum semper !qwerty nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Praesent ac massa at ligula laoreet iaculis.</div></textarea><div attr="398" type="398" class="statusboxes border border-warning status_398 jumbotron"><h3 class="pull-left title"><div id="#398" attr="398" class="title_s_2copy posted" value=" 123456"> 123456</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a attr="398" type="398" class="btn edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status">Edit</a></li> <li><a type="398" class="btn delete_4_session hidden_text_delete_398 glyphicon glyphicon-trash delete_status_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><legend><span style="font-size: 13.5px;" class=" data_s_2copy" type="398"><div class="descrip" data-id="398"><div>Vivamus elementum semper <a class="btn btn-link" href="hash_sys.php?tag=qwerty"> !qwerty </a> nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Praesent ac massa at ligula laoreet iaculis.</div> <br></div></span></legend><b class="posted"><small>Posted by:- <a href="home.php?u=aboutthecreator"><img src="../user/user/142/ThuJul1821235420191075.jpg" height="20px" width="20px"> aboutthecreator</a> on December 19, 19</small></b><small><br><span class="pull-left spinner_status398"></span><legend><a type="like" class="btn btn-warning status_like_398 like" attr="398">Like</a> <span class="label label-info">0</span> | <a type="unlike" class="btn btn-danger status_unlike_398 unlike" attr="398">Dislike</a> <span class="label label-info">0</span> | <a class="btn btn-primary share_btn share_398" title=" 123456" type="share" id="398">Copy</a></legend></small><span class="edit-spinner"></span><h4><a id="398" class="btn btn-default collap-btn">Comments</a></h4> <!-- Collapsible Element HTML --> <div id="toggle398" class="collapse scroll-comments"> <textarea id="reply_textarea_398" update-detail="398" class="atwho-inputor status_reply_398 input-custom2" placeholder="comment's"></textarea><span class="pull-left spinner_comment_post398"></span><button id="reply_butn_398" attr="398" type="b" class="btn btn-warning pull-right btn-sm reply_butn reply_398">Reply</button><span id="status_spinner_r"></span></div></div><b class="i-select"><i class="no" style="display:none;" no="397">397,</i> <div type="397" class="hide hidden_edit_4_session session_editor397 jumbotron" style="display: none;"><a type="397" class="btn pull-right close_edit" title="Close without editing">Close X</a><input type="text" class="form-control title_s_edit title_s_397" name="status_title" value=" 12345" placeholder="Title"><span> </span><textarea id="wall_edit_397" type="397" rows="5" cols="50" class="session_edit text_value_397" wrap="hard" placeholder="whats up aboutthecreator"> <div>Vivamus <a class="btn btn-link" href="hash_sys.php?tag=qwerty"> !qwerty </a> elementum semper nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. <a class="btn btn-link" href="hash_sys.php?tag=bart"> !bart </a> Praesent ac massa at ligula laoreet iaculis.</div></textarea><br><span class="pull-left spinner_edit397"></span><button style="float:right;" value="397" type="a" class="btn btn-warning btn btn-large btn-lg post-s-edit">Update</button></div></b><textarea class="hidden_textarea hidden_value397" disabled=""><div>Vivamus !qwerty elementum semper nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. !bart Praesent ac massa at ligula laoreet iaculis.</div></textarea><div attr="397" type="397" class="statusboxes border border-warning status_397 jumbotron"><h3 class="pull-left title"><div id="#397" attr="397" class="title_s_2copy posted" value=" 12345"> 12345</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a attr="397" type="397" class="btn edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status">Edit</a></li> <li><a type="397" class="btn delete_4_session hidden_text_delete_397 glyphicon glyphicon-trash delete_status_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><legend><span style="font-size: 13.5px;" class=" data_s_2copy" type="397"><div class="descrip" data-id="397"><div>Vivamus <a class="btn btn-link" href="hash_sys.php?tag=qwerty"> !qwerty </a> elementum semper nisi. Donec sodales sagittis magna.</div> <div> </div> <div>Fusce egestas elit eget lorem. Pellentesque auctor neque nec urna.</div> <div> </div> <div>Quisque rutrum. Integer tincidunt.</div> <div> </div> <div>Morbi vestibulum volutpat enim. Curabitur at lacus ac velit ornare lobortis.</div> <div> </div> <div>Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. <a class="btn btn-link" href="hash_sys.php?tag=bart"> !bart </a> Praesent ac massa at ligula laoreet iaculis.</div> <br></div></span></legend><b class="posted"><small>Posted by:- <a href="home.php?u=aboutthecreator"><img src="../user/user/142/ThuJul1821235420191075.jpg" height="20px" width="20px"> aboutthecreator</a> on December 19, 19</small></b><small><br><span class="pull-left spinner_status397"></span><legend><a type="like" class="btn btn-warning status_like_397 like" attr="397">Like</a> <span class="label label-info">0</span> | <a type="unlike" class="btn btn-danger status_unlike_397 unlike" attr="397">Dislike</a> <span class="label label-info">0</span> | <a class="btn btn-primary share_btn share_397" title=" 12345" type="share" id="397">Copy</a></legend></small><span class="edit-spinner"></span><h4><a id="397" class="btn btn-default collap-btn">Comments</a></h4> <!-- Collapsible Element HTML --> <div id="toggle397" class="collapse scroll-comments"> <textarea id="reply_textarea_397" update-detail="397" class="atwho-inputor status_reply_397 input-custom2" placeholder="comment's"></textarea><span class="pull-left spinner_comment_post397"></span><button id="reply_butn_397" attr="397" type="b" class="btn btn-warning pull-right btn-sm reply_butn reply_397">Reply</button><span id="status_spinner_r"></span></div></div> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br> update_id1:- ids:- 0398<br></div> </div> -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand if you want i'll send the sql data securely to your email for you to see. -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand it contains json value passed from jquery got through DOM check the javascript for details and here is the update_id variable decoding the array: -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
here is the function @Barand -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand the $i feature passed in foreach loop. if that's not an incrementing feature then what should i do to increment the variables value as using loops repeatedly creates ajax to produce duplicate values. i'mm also post the ajax here for you to inspect. i'm using the quote feature because there is no code feature in the reply textbox sorry again. -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barand i'm trying to pass on the array values from unique and ids in to the totalUpdates class the problem is i'm using the foreach loop's incrementing feature $i to feed values from update_id and ids array and the incrementing feature is not working as the ajax is not fetching values after 2 posts. i'm sorry for using quote feature as code feature was not available -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
here is the total updates class function: here is the full code: -
Not able to increment in foreach loop to get the values of an array
narutofan replied to narutofan's topic in PHP Coding Help
@Barandits lengthy boss. -
hi, i’m currently facing a new problem (i managed to use array_unique function successfully but i face this problem)with my php loop. i couldn’t seem to increment in my foreach loop to get the value of an array. here is my code: $update_id1=Array ( [0] => 398 [1] => 397 [2] => 393 [3] => 391 [8] => ); //$i=0; foreach ($update_id1 as $i => $v) { $ex= explode(",", $v); $unique=array_unique($ex); //f$ketch username from update table in db and inject it to the feed query. $imp_id= implode(',', $ids); //$id1=$ids[$i]; // $x=0; // for($x=0;$x<count(unique);$x++){ echo 'ids:- '.$i; print_r($unique[$i]); echo '<br>'; //} $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$unique[$i],$load); //$i++; } i tried every method nothing seems to work can anyone help me in this regard please.
-
ok @requinix here is the situation i created this script with an online tutorial long ago but it was a simple one involving only one session name and it worked fine but later i tried to involve other users name to fetch what updates they have posted along with the session name. That's when the problem's started to follow the ajax seems to only produce repeated post values(397 &396) in what they were fetching from the database. But its a lot complex involving three other and growing number of other users who might give feedback to the project through a tinymce instance. after folllowing your advice i found that it was the ajax that seems to be producing duplicate values, i used the querybox in phpmyadmin to get the desired unique results for the mysql query but the ajax in infinite scrolling script is the culprit, i don't know how to fetch unique values for my project other than thisi'm looking for ideas or guidance in making it a working script. other than this javascript is not my forte if you need further info pl ask me bluntly too i dont mind its a learning curve with a teacher for me.
-
i'm indulged in a project(started 5 months ago) requiring infinite scrolling pagination where i couldn't get the javascript working because it keeps on producing duplicate posts from php script. I tried the mysql query in phpmyadmin and it didnt produce any duplicate queries and i require help in getting a seamless pagination without duplicate queries like facebook for the project to take off. Here are the scripts that i have been working so, far. Javascript from home page: 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> "+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++; // alert(load+" "+sess_count); if(load * 2 > sess_count){ $(".message").html("<h1>no more posts to show </h1>"); }else{ $.post("st&com.php", {"load":load,"sess_count":sess_count},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(); }); } } }); } $(document).on("click", ".close_edit",function(){ var id=$(this).attr("type"); $(".session_editor"+id).hide(); $(".status_"+id).show(); }); php script(it's lengthy): $f = array(); $ids= array(); $stmt= $conn->prepare("select friend_one, friend_two from friends where (friend_one=:session OR friend_two=:session) and (friend_one>=:session or friend_two>=:session) and accepted='1'"); $stmt->bindparam(":session",$_SESSION['uname']); $stmt->execute(); $f=$stmt->fetchAll(); $f_count=count($f); $ids= ff($f, $project); $i=0; while($i<$f_count){ $id=$v; print_r($ids[$i]); //fetch username from update table in db and inject it to the feed query. $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$load); $i++; /* *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*2>$sess_count){ $total_sess_count=0; } else { $total_sess_count=$project->totalupdatescount($id); } foreach ($totalUpdates as $j=>$row1) { $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']; if ($avatar!=""){ $feed_pic='../user/user/'.$uid.'/'.$avatar; } else { $feed_pic='img/avatardefault.png'; } $words=explode(" ", $data1); $count_words=count($words); if($count_words>180){ $partial_data1= join(" ", array_slice($words,0,150)); $more="<button class='btn btn-link more' data-id='".$updateid."'>...More</button>"; }else{ $partial_data1=$data1; $more=""; } $vote_up_count=$project->voteUpdateCheck($updateid, $_SESSION['id']); if($vote_up_count[0][0]>0){ $vote_like=TRUE; } else { $vote_like=FALSE; } if($vote_up_count[0][1]>0){ $vote_dislike=TRUE; } else { $vote_dislike=FALSE; } include 'ratings/vote_count.php'; if ( $vote_like==TRUE && $vote_dislike==FALSE) { $like='<a type="liked" class="btn btn-warning liked status_like_'.$updateid.' " attr="'.$updateid.'">Liked</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$updateid.' " attr="'.$updateid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } elseif ($vote_dislike==TRUE && $vote_like==FALSE) { $like='<a type="like" class="btn btn-warning status_like_'.$updateid.' like" attr="'.$updateid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="disliked" class="btn btn-danger disliked status_unlike_'.$updateid.'" attr="'.$updateid.'">Disliked</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } else { $like='<a type="like" class="btn btn-warning status_like_'.$updateid.' like" attr="'.$updateid.'">Like</a> <span class="label label-info">'.$num_likes[0].'</span>'; $unlike='<a type="unlike" class="btn btn-danger status_unlike_'.$updateid.' unlike" attr="'.$updateid.'">Dislike</a> <span class="label label-info">'.$num_unlikes[0].'</span>'; } $share_button=""; $hidden_text= '<textarea class="hidden_textarea hidden_value'.$updateid.'" disabled>'.$data.'</textarea>'; $share_button="<a class='btn btn-primary share_btn share_".$updateid."' title='".$title."' type='share' id='".$updateid."'>Copy</a>"; $reply_btn=""; if ($author==$_SESSION['uname'] || $account_name==$_SESSION['uname']) { $statusdeletebutton='<li>' . '<a type="'.$updateid.'" class="btn delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_status_btn" title="Delete this status and its replies">Remove</a></li>'; $edit_btn='<li>' . '<a attr="'.$updateid.'" type="'.$updateid.'" class="btn edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'; $statusui_edit="<div type='".$updateid."' class='hide hidden_edit_4_session session_editor".$updateid." 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> </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>" ; }else{ $statusdeletebutton=""; $edit_btn="<li class='posted'>You are not the owner of this Post</li>"; $statusui_edit=""; $report_btn='<li><a href="#'.$updateid.'" attr="'.$_SESSION['id'].'" account-name="'.$author.'" type="'.$updateid.'" id="'.$f_uid.'" class="report_offence glyphicon glyphicon-warning-sign" title="Edit this status" >Report</a></li>'; } echo $statusui_edit.''. $hidden_text.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes border border-warning status_'.$updateid.' jumbotron">' . '<h3 class="pull-left title">' . '<div id="#'.$updateid.'" attr="'.$updateid.'" class="title_s_2copy posted" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>' . '<span class="pull-right">' . '<div class="dropdown">' . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" >' . '<span class="glyphicon glyphicon-edit"></span></button>' . '<ul class="dropdown-menu">' .$edit_btn .' '. $statusdeletebutton .''.$report_btn.'</ul></div></span><br><hr>' . '<legend><span style="font-size: 13.5px;" class=" data_s_2copy" type="'.$updateid.'" >' . '<div class="descrip" data-id="'.$updateid.'">' . html_entity_decode($partial_data1)." <br>".$more.'</div></span></legend><b class="posted"><small>Posted by:- <a href="home.php?u='.$author.'"><img src="'.$feed_pic.'" height="20px" width="20px"> '.$author. '</a> on '.$datemade.'</b>' . '<br><span class="pull-left spinner_status'.$updateid.'"></span><legend>'.$like.' | '.$unlike. ' | '.$share_button.'</legend></small><span class="edit-spinner"></span>'; ?> <h4><a id="<?php echo $updateid;?>" class="btn btn-default collap-btn">Comments</a></h4> <!-- Collapsible Element HTML --> <div id="toggle<?php echo $updateid;?>" class="collapse scroll-comments"> <?php // Fetch Comments of update $totalComments=$project->totalComments($_SESSION['uname'],$friend,$updateid); foreach($totalComments as $row1){ $status_reply_id=$row1['comment_id']; $reply_d=htmlentities($row1['comment_body']); $reply_data= stripslashes($reply_d); $reply_osid=$row1['os_id']; $reply_date=$row1['time_c']; $reply_author=$row1['author_c']; $reply_data1= hashtags($reply_data); //$reply_data1= taggingsys($reply_data0); //$reply_data1= taggingsys($reply_data0); $datemade_r = strftime("%B %d, %y", strtotime($reply_date)); include 'ratings/vote_count4comments.php'; $vote_up_count_r=$project->voteReplyCheck($_SESSION['id'], $status_reply_id); if($vote_up_count_r[0][0]>0){ $vote_like_r=TRUE; } else { $vote_like_r=FALSE; } if($vote_up_count_r[0][1]>0){ $vote_dislike_r=TRUE; } else { $vote_dislike_r=FALSE; } if ( $vote_like_r==TRUE && $vote_dislike_r==FALSE) { $like_r='<a type="liked" class="btn btn-warning status_liker_'.$status_reply_id.' liked_r" attr="'.$status_reply_id.'">Liked</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unliker_'.$status_reply_id.' unlike_r" attr="'.$status_reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } elseif ($vote_dislike_r==TRUE && $vote_like_r==FALSE) { $like_r='<a type="like" class="btn btn-warning status_liker_'.$status_reply_id.' like_r" attr="'.$status_reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unliked" class="btn btn-danger status_unliker_'.$status_reply_id.' disliked_r" attr="'.$status_reply_id.'">Disliked</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } else { $like_r='<a type="like" class="btn btn-warning status_liker_'.$status_reply_id.' like_r" attr="'.$status_reply_id.'">Like</a> <span class="label label-info">'.$num_likes_r[0].'</span>'; $unlike_r='<a type="unlike" class="btn btn-danger status_unliker_'.$status_reply_id.' unlike_r" attr="'.$status_reply_id.'">Dislike</a> <span class="label label-info">'.$num_unlikes_r[0].'</span>'; } $pic=$project->viewByUname($reply_author); $uid=$pic['user_id']; $avatar=$pic['avatar']; if ($avatar!=""){ $feed_r_pic='../user/user/'.$uid.'/'.$avatar; } else { $feed_r_pic='img/avatardefault.png'; } if ($reply_author==$_SESSION['uname'] ) { $reply_delete_button='<li><a type="'.$status_reply_id.'" class="btn delete_reply_btn glyphicon glyphicon-trash delete_reply_"'.$status_reply_id.'" title="Delete this comment"> Remove</a></span></li>'; } else{ $reply_delete_button=""; } echo ' <div class="replyboxes pull-left reply_' .$status_reply_id.'">' . 'Reply by:- ' . '<a href="home.php?u='.$reply_author. '"><img src="'.$feed_r_pic.'" height="20px" width="20px"> '.$reply_author.'</a>' . '<span class="pull-right">'.$datemade_r . '<b class="dropdown"> <small><span class="btn btn-xs btn-danger dropdown-toggle pull-right" data-toggle="dropdown" > <span class="glyphicon glyphicon-edit"></span></span> <ul class="dropdown-menu">'.$reply_delete_button . '<li><a class="glyphicon glyphicon-warning-sign" href="report.php?u='.$reply_author.'"> Report</a><li></ul></span>' . '</small></b><br><legend>'. html_entity_decode($reply_data1).'<br><span class="pull-left spinner_comment'.$status_reply_id.'"></span>'.$like_r.'|'.$unlike_r.'</legend></div>'; } echo '<textarea id="reply_textarea_'.$updateid.'" update-detail="'.$updateid.'" class="atwho-inputor status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>' . '<span class="pull-left spinner_comment_post'.$updateid.'"></span><button id="reply_butn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_butn reply_'.$updateid.'">Reply</button><span id="status_spinner_r"></span></div></div>'; } } } DB query from classes.php: public function totalUpdates($friend,$session, $load) { try{ $sql2="SELECT distinct update_id,update_body,time,title,user_id_u,account_name,author,data FROM updates where author in (:friend,:session) order by time desc limit $load,2"; $stmth= $this->_db->prepare($sql2);//Check here syntax of $db $stmth->bindValue(":session",$session); $stmth->bindValue(":friend",$friend); $stmth->execute(); return $stmth->fetchAll(); } catch (PDOException $ei){ echo $ei->getMessage(); } } i hope some expert who is interested in the problem can share his views and help me solve the javascript bug that keeps on repeatedly producing duplicate values and not fetching all the remaining posts from db.