Advertisement
akhyrul

Contoh nampilin threaded/nested comment

May 20th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. // ini fungsi rekursif
  2. function show_comment($comment)
  3. {
  4.     echo "<li>";
  5.     echo $comment->isi;
  6.    
  7.     // $children = SELECT * FROM comments WHERE parent_id = $comment->id;
  8.     // pokoknya ini ngitung jumlah children
  9.     if(mysql_num_rows($children) > 0)
  10.     {
  11.         echo "<ol>";
  12.         while($child = mysql_fetch_object($children))
  13.         {
  14.             show_comment($child);
  15.         }
  16.         echo "</ol>";
  17.     }
  18.  
  19.     echo "</li>";
  20. }
  21.  
  22. // mulai sini main loop
  23. // $comments = SELECT * FROM comments WHERE post_id = $post_id AND parent_id = 0
  24. echo "<ol>";
  25. while($comment = mysql_fetch_object($comments))
  26. {
  27.     show_comment($comment)
  28. }
  29. echo "</ol">;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement