This is for an ecommerce site. This is supposed to display a complete list of categories with their ids next to it. The names should be like this
Animals : Pet Supplies : Dog Supplies : Dog Bowls, Feeders & Waterers 41

The problem is that each parent category with subcategories gets skipped, showing only the subcategories.

I need this to display all of them.

Thanks

    function setCategories()
    {
        $sql_select_categories = $this->db->query("SELECT c.category_id FROM " . DB_PREFIX . "categories c WHERE 
            (SELECT count(*) FROM " . DB_PREFIX . "categories p WHERE p.parent_id=c.category_id)=0");

        while ($category_details = $this->db->fetch_array($sql_select_categories))
        {
            $this->categories[] = array('id' => $category_details['category_id'], 'name' => $this->categories_array[$category_details['category_id']][0]);
        }
    }
Member Avatar for LastMitch

@Tristan2036

The problem is that each parent category with subcategories gets skipped, showing only the subcategories.

I think you might need a Join.

This array doesn't make sense:

$this->categories[] = array('id' => $category_details['category_id'], 'name' => $this->categories_array[$category_details['category_id']][0]);

I read your code and I'm not sure what you are asking? Are you asking someone to write out a code that displayed this:

Animals : Pet Supplies : Dog Supplies : Dog Bowls, Feeders & Waterers 41

Okay I'll explain a little better, It seems like this is skipping over parent categegories like
Animals
or
Animals : Pet Supplies
or Animals : Pet Supplies : Dog Supplies
and instead only showing Animals : Pet Supplies : Dog Supplies : Dog Bowls, Feeders & Waterers
It ignores the parent level and shows only the subcategory with parents behind it in the line.

Since Animals has subcategories it seems to skip it and display only the bottom level categories in a breadcrumbs format and thereby shows the bottom level id but sips the parent for example animals.

It does this al througout the category tree.

It want it to show all if them parents included in breadcrumb format more like this

Animals
Animals : Pet Supplies
Animals : Pet Supplies : Dog Supplies
Animals : Pet Supplies : Dog Supplies : Dog Bowls, Feeders & Waterers

Hope this clarifies.

Member Avatar for LastMitch

@Tristan2036

Diafol provide you a nice link about your issue. Just follow the example and follow the format of the arrays and it will echo out what you want it to be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.