sofian Posted June 15, 2011 Share Posted June 15, 2011 hi i have this code on my script : $arr = array( 'avatar'=>$client['avatar'],'message'=>stripslashes($_POST['message']),'username'=>$client['uname'],'created'=>time() ); echo comment_display($arr); if i submited 4 comments of echo comment_display($arr); start from post 1 it sort them like this : post 4 post 3 post 2 post 1 post 1 , post 2 above post 1 , post 3 above post 2 , post 4 above post 3 but i want them like this : post 1 post 2 post 3 post 4 post 1 , post 2 under post 1 , post 3 under post 2 , post 4 under post 3 how can i make the " echo comment_display($arr); " become under the last post not above . thank you verry much Quote Link to comment https://forums.phpfreaks.com/topic/239471-i-need-help-with-comments-look-please/ Share on other sites More sharing options...
cyberRobot Posted June 16, 2011 Share Posted June 16, 2011 comment_display() appears to be a user-defined function. What does the code look like? In the meantime, you could look into the various array sorting functions: http://php.net/manual/en/array.sorting.php Quote Link to comment https://forums.phpfreaks.com/topic/239471-i-need-help-with-comments-look-please/#findComment-1230286 Share on other sites More sharing options...
punk_runner Posted June 16, 2011 Share Posted June 16, 2011 Try: $newArr = array_reverse($arr); echo $newArr; or asort($arr); Quote Link to comment https://forums.phpfreaks.com/topic/239471-i-need-help-with-comments-look-please/#findComment-1230327 Share on other sites More sharing options...
sofian Posted June 16, 2011 Author Share Posted June 16, 2011 comment_display() appears to be a user-defined function. What does the code look like? In the meantime, you could look into the various array sorting functions: http://php.net/manual/en/array.sorting.php thank you cyberRobot for your help and reply . i tryed to use from here http://php.net/manual/en/array.sorting.php but i did not succes . but here all the code that i have for the comments : 1- the script : <script> $(".quick_comment").click(function() { $(this).next().next().css("display","block"); $(this).next().next().find(".commentmessage").focus(); return false; }); $(".commentsubmit").click(function() { if ($(this).prev()[0].value != "") { var thiscomment = $(this).parents(".quick_comment_form"); var cbox = thiscomment.next().next(); var mbox = thiscomment.find(".commentmessage"); var tbox = thiscomment.next(); cbox.html("<img src=\"'.uhome().'/files/loading.gif\" /> Submitting"); $.post("'.uhome().'/index.php?p=jquery/comment_publish", {message:mbox[0].value,target_id:tbox[0].value}, function(data){ cbox.html(""); $(".quick_comment_form").css("display","none"); cbox.after(data); mbox.attr("value",""); },"html" ); return false; } }); </script> 2- the jquery code : ( function comment_publish ) $arr = array( 'avatar'=>$client['avatar'],'message'=>stripslashes($_POST['message']),'username'=>$client['uname'],'created'=>time() ); echo comment_display($arr); 3- function comment_display function comment_display($row = array()) { if (!$row['avatar']) { $res = sql_query("select avatar from ".tb()."accounts where id='{$row['uid']}'"); $row2 = sql_fetch_array($res); if (!$row2['avatar']) $row['avatar'] = 'undefined.jpg'; else $row['avatar'] = $row2['avatar']; }; return ' <div class="user_comment"> <table width="100%"> <tr> <td class="user_post_left" width="40" valign="top">'.avatar($row,25).'</td> <td class="user_post_right" valign="top"> <strong>'.url('u/'.$row['username'], $row['username']).'</strong> '.h($row['message']).' <div class="att_bottom">'.get_date($row['created']).'</div></td> </tr> </table> </div> '; } thank you verry much Quote Link to comment https://forums.phpfreaks.com/topic/239471-i-need-help-with-comments-look-please/#findComment-1230650 Share on other sites More sharing options...
sofian Posted June 16, 2011 Author Share Posted June 16, 2011 Try: $newArr = array_reverse($arr); echo $newArr; or asort($arr); thank you punk_runner for this help and reply i cant use $newArr = array_reverse($arr); because i need the comment_display function and this code asort($arr); i tryed it but the result not change . thank you verry much Quote Link to comment https://forums.phpfreaks.com/topic/239471-i-need-help-with-comments-look-please/#findComment-1230654 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.