azmicolejr

Untitled

Apr 26th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2. include "config.php";
  3.  
  4. function punya_child($id_kategori = NULL)
  5. {
  6. $result = mysql_query('SELECT COUNT(id_kategori) AS jumlah_child FROM category WHERE id_parent = \''.$id_kategori.'\'');
  7. $data = mysql_fetch_assoc($result);
  8. if($data['jumlah_child'] > 0) return TRUE;
  9. return FALSE;
  10. }
  11.  
  12. function hirarki($id_kategori = NULL)
  13. {
  14. if($id_kategori === NULL)
  15. {
  16. $result_top_level = mysql_query('SELECT * FROM category WHERE id_parent IS NULL');
  17. if(mysql_num_rows($result_top_level) > 0)
  18. {
  19. echo '<ul class="category">';
  20. while($row_top_level = mysql_fetch_assoc($result_top_level))
  21. {
  22. echo "<li class='category'>", $row_top_level['kategori'];
  23. if(punya_child($row_top_level['id_kategori']))
  24. {
  25. hirarki($row_top_level['id_kategori']);
  26. }
  27. echo '</li>';
  28. }
  29. echo '</ul>';
  30. }
  31. }
  32. else
  33. {
  34. $result_child = mysql_query('SELECT * FROM category WHERE id_parent = \''.$id_kategori.'\'');
  35. if(mysql_num_rows($result_child) > 0)
  36. {
  37. echo '<ul class="subcategory">';
  38. while($row_child = mysql_fetch_assoc($result_child))
  39. {
  40. echo "<li><a href='cat.php?kategori=$row_child[kategori]'>", $row_child['kategori'];
  41.  
  42. if(punya_child($row_child['id_kategori']))
  43. {
  44. hirarki($row_child['id_kategori']);
  45. }
  46. echo '</li>';
  47. }
  48. echo '</ul></a>';
  49. }
  50. }
  51.  
  52. }
  53. hirarki();
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment