narutofan Posted December 25, 2019 Share Posted December 25, 2019 (edited) 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. Edited December 25, 2019 by narutofan Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/ Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 Why don't you post your actual code (that code won't execute past the first line) and tell us what you are trying to achieve, not just how you are failing to do whatever it is. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572889 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) @Barandits lengthy boss. Edited December 25, 2019 by narutofan Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572890 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) here is the total updates class function: Quote public function totalUpdates($friend,$session,$var_id, $load) { try{ // $sql2="SELECT distinct update_id,update_body,time,title,user_id_u,account_name,author,data FROM updates WHERE author=:friend and account_name=:session order by time desc limit $load,2"; $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 >:update_id_all 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->bindValue(":update_id_all",$var_id); //$stmth->bindValue(":update_id2",$update_id2); $stmth->execute(); return $stmth->fetchAll(); } catch (PDOException $ei){ echo $ei->getMessage(); } } here is the full code: Quote $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(",", $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:- '.$x; print_r($unique[$x]); echo '<br>'; $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$unique[$i],$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="<b class='i-select'><i class='no' style='display:none;' no='".$updateid."'>".$updateid.",</i> <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></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>'; } } //} //} //} // } // } } Edited December 25, 2019 by narutofan Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572891 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 Then tell us what the code you posted is supposed to do. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572892 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 Please use the "code" icon for code, not the "quote" Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572893 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) @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 Edited December 25, 2019 by narutofan Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572894 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 10 minutes ago, narutofan said: i'm using the foreach loop's incrementing feature What incrementing feature? Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572895 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) @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. Quote //logic for infinite scroll for session user. 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[x]; // 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 * 2 < 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(); }); } } }); } i'm using the quote feature because there is no code feature in the reply textbox sorry again. Edited December 25, 2019 by narutofan to include the tag Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572896 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 in the code foreach ($array as $i => $v) $i = index of the current element $v = value of the current element You use a function ff() as in $ids= ff($f, $project); but I can't see it defined anywhere. What does it do? Then I'll have some idea of what the data in $ids looks like. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572897 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 here is the function @Barand Quote function ff(&$s, $project) { $output=array(); $verify_friend=array(); foreach ($s as $i=> $r ){ $r["friend_one"] == $_SESSION['uname'] ? $friends[]= $r["friend_two"] : $friends[] = $r["friend_one"]; //$r["friend_two"] == $_SESSION['uname'] ? $friends[]= $r["friend_one"] : $friends[] = $r["friend_two"]; $verify_friend= $project->totalids($_SESSION['uname'],$friends[$i]); /*_4_session",function(e){ e.preventDefault(); var id=$(this).attr("type"); $(".session_editor"+id).hide(); }); foreach ($friends as $v) { echo '<br><h2>'; print_r($v); echo '</h2></br>'; echo '<br>'; var_dump($verify_friend); array_push($totalids, $verify_friend); var_dump($totalids); }*/ array_push($output, $friends); } return $friends; } Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572898 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 OK, so ff() returns an array of the user's friend ids. The next uncommented line is foreach ($update_id1 as $i => $v) { What does $update__id1 contain (there doesn't appear to be a prior reference)? Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572899 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) @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: Quote $update_id1= json_decode(stripslashes($_POST['update_id1'])); $load= (int)($_POST['load']); $sess_count=(int)($_POST['sess_count']); Edited December 25, 2019 by narutofan Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572903 Share on other sites More sharing options...
Barand Posted December 25, 2019 Share Posted December 25, 2019 (edited) As I obviously cannot run the script to see for myself, perhaps you would be kind enough to give me an example of the data being passed. My main concern is the structure of your code. You are running a query to get an array of ids and then looping through that resulting array to run queries based on those ids. Running queries within loops is extremely inefficient. You should be running a single query which joins the tables on those ids to get the data you require. Edited December 25, 2019 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572904 Share on other sites More sharing options...
narutofan Posted December 25, 2019 Author Share Posted December 25, 2019 @Barand if you want i'll send the sql data securely to your email for you to see. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572905 Share on other sites More sharing options...
narutofan Posted December 26, 2019 Author Share Posted December 26, 2019 @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> Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572910 Share on other sites More sharing options...
narutofan Posted December 29, 2019 Author Share Posted December 29, 2019 @Barand are you there bro show me a sign Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572956 Share on other sites More sharing options...
Barand Posted December 29, 2019 Share Posted December 29, 2019 Still waiting to know what's being sent by your ajax request Example... Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572958 Share on other sites More sharing options...
Psycho Posted December 30, 2019 Share Posted December 30, 2019 As @Barand has stated, without knowing what $update_id1 contains and it's exact structure, it is impossible to know what the problem is, but I have a couple of comments 1. Your original post contained this $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>'; } Assuming there was a "real" array defined, within the foreach() loop the code first does an explode on the value - even though your example values have no commas for the explode. Then you store the unique values in a new variable called $unique. Then you do an implode of an array called $ids - which has never been defined. I think you meant to do an implode of the unique values ??? 2. While this line may work $r["friend_one"] == $_SESSION['uname'] ? $friends[]= $r["friend_two"] : $friends[] = $r["friend_one"]; . . . it is an awkward implementation. This is much more precise and readable. $friends[] = ($r["friend_one"] == $_SESSION['uname']) ? $r["friend_two"] : $r["friend_one"]; But, I'm betting there is a better way to determine the value within your query. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1572979 Share on other sites More sharing options...
narutofan Posted January 2, 2020 Author Share Posted January 2, 2020 @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. Quote Link to comment https://forums.phpfreaks.com/topic/309748-not-able-to-increment-in-foreach-loop-to-get-the-values-of-an-array/#findComment-1573068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.