Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "config.php";
- function punya_child($id_kategori = NULL)
- {
- $result = mysql_query('SELECT COUNT(id_kategori) AS jumlah_child FROM category WHERE id_parent = \''.$id_kategori.'\'');
- $data = mysql_fetch_assoc($result);
- if($data['jumlah_child'] > 0) return TRUE;
- return FALSE;
- }
- function hirarki($id_kategori = NULL)
- {
- if($id_kategori === NULL)
- {
- $result_top_level = mysql_query('SELECT * FROM category WHERE id_parent IS NULL');
- if(mysql_num_rows($result_top_level) > 0)
- {
- echo '<ul class="category">';
- while($row_top_level = mysql_fetch_assoc($result_top_level))
- {
- echo "<li class='category'>", $row_top_level['kategori'];
- if(punya_child($row_top_level['id_kategori']))
- {
- hirarki($row_top_level['id_kategori']);
- }
- echo '</li>';
- }
- echo '</ul>';
- }
- }
- else
- {
- $result_child = mysql_query('SELECT * FROM category WHERE id_parent = \''.$id_kategori.'\'');
- if(mysql_num_rows($result_child) > 0)
- {
- echo '<ul class="subcategory">';
- while($row_child = mysql_fetch_assoc($result_child))
- {
- echo "<li><a href='cat.php?kategori=$row_child[kategori]'>", $row_child['kategori'];
- if(punya_child($row_child['id_kategori']))
- {
- hirarki($row_child['id_kategori']);
- }
- echo '</li>';
- }
- echo '</ul></a>';
- }
- }
- }
- hirarki();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment