Jump to content

List categories by type and list subcategories by order


afaaro

Recommended Posts

function test_categories(){
    $array = array();
    $result = dbquery("SELECT * FROM ".CONTENT_CATEGORIES);
    while($data = dbarray($result)){
        $array[$data['type']]['parent'][] = $data;
    }
    return $array;
}
function admin_list($level = FALSE){
    global $class;
    echo "<table cellspacing='0' cellpadding='0' class='table table-responsive tbl-border center'>";
    foreach(test_categories() as $category_type => $parents){
        echo "<tr class='$class'><th>".$category_type."</th></tr>";
        if(is_array($parents) && !empty($parents)){
            foreach($parents as $parent => $children){
                if(is_array($children) && !empty($children)){
                    foreach($children as $child){
                        $indent = str_repeat("--", $level);
                        $class = bgclass();                     
                        echo "<tr class='$class'><td>".$indent="--".$child['name']."</td></tr>";
                    }
                }
            }
        }
    }
    echo "</table>";
}
admin_list();  

but i need to show subcategories like this and how

Categories

-- subcategories

---- subcategories

Link to comment
Share on other sites


now this is how am getting

News
— News Category
— sub categories
Diinta
— Diinta category

and this is how i want

News
— News Category
—— sub categories
Diinta
— Diinta category 

 

Edited by afaaro
Link to comment
Share on other sites

You really need to work on your communication skills.

 

Don't see the difference in your two examples unless it is the extra dashes on 'subcategory'. In any case, that is a "presentation" problem, not a php or logic problem. Show us your code and then we can perhaps fix it. But - really - your current posted code is not the way to go. Not at all.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.