Remove link in supersub category PHP Mysql

巧了我就是萌 提交于 2019-12-24 17:18:08

问题


I have a problem with active link that i've created. I want to make the Sub Category doesn't have any link, only the supersub have link for each supersub category.

The example like: 1. painting (category), 1.1 HOBE (sub category), 1.1.1 Sealer, 1.1.2 Wall Paint (supersub category)

The table contain: id_kategori, kategori, id_parent

This is my code:

<?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();
?>

I really thankful if someone can help me how solve this problem. Thank you

来源:https://stackoverflow.com/questions/29876848/remove-link-in-supersub-category-php-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!