Welcome Guest, Not a member yet? Register   Sign In
Logical Problem With category and sub-category
#7

[eluser]woomacoder[/eluser]
[quote author="Dam1an" date="1240616391"]I still don't see the point of storing the number of sub categories in the cats table, as you risk getting out of sync, and its very quick to do a count on the number of records where parent_id == cat_id

Could you not do something like

Code:
<?php
$categories = get_categories();
foreach($categories as $category) {
    // Print the top level category
    echo $category->name, '<br />';
    
    // get the sub categories
    $subcategories = get_categories($category->id);
    foreach($subcategories as $subcategory) {
        echo '- ', $subcategory->name, '<br />';
    }
}

function get_categories($parent_id = 0) {
    $this->db->where('parent_id', $parent_id);
    return $this->db->get('categories')->result();
}
?&gt;
[/quote]

Yeah! Smile Great solution! Wink thank you!


Messages In This Thread
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 06:00 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 10:36 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 11:07 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 12:14 PM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 12:39 PM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 04:44 PM
Logical Problem With category and sub-category - by El Forum - 04-25-2009, 02:32 AM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:34 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:49 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:56 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:02 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:08 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:16 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:18 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:21 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:24 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:26 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 06:06 PM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:31 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:48 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:51 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:56 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:12 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:18 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:36 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 09:07 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 09:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB