afaaro Posted April 22, 2015 Share Posted April 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 22, 2015 Share Posted April 22, 2015 Why not simplify your whole logic and simply do the query with an order by clause and then output it using the while loop on your query results? Quote Link to comment Share on other sites More sharing options...
afaaro Posted April 22, 2015 Author Share Posted April 22, 2015 (edited) 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 April 22, 2015 by afaaro Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 22, 2015 Share Posted April 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
afaaro Posted April 22, 2015 Author Share Posted April 22, 2015 Thank you I have done it Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 23, 2015 Share Posted April 23, 2015 Happy to hear that. Was tired of trying to communicate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.