Why do i get 2 of each?


I am trying to pull out categories and sub categories. I have the following 2 methods:

    public function selectAllCategories(){

        $query = "SELECT * FROM tbl_category WHERE deleted = 0
            ORDER BY date_added DESC";
        $result = mysql_query($query);
        return $result;

    public function selectAllSubCategories(){

        $query = "SELECT s.ID as TheID,
                         s.name as TheName,
                 FROM tbl_subcategory s
                 INNER JOIN tbl_category c
                 ON s.category_ID = c.ID
                 WHERE s.deleted = 0 AND c.deleted = 0 
                 ORDER BY s.date_added DESC";
        $result = mysql_query($query);
        return $result;

But i see this:


I have 2 categories in the table tbl_category, called Mens & Ladies, then i have a series of sub categories in each.

But as you can see in the image the subcategories show in pairs? why is this?

The select statement being used for this is selectAllSubCategories, as shown in my methods…

Can anyone help?



Sorry for the two threads i thought this was specific to the methods i am using :wink:

Anyway, it looks like the best method to do this properly is combining the two tables into one, and then link to the parent category. As you guys in the forum always offer the best advice, i will now try to implement this as i know its the proper way to do it.

I will let you know if i get stuck :smiley:

Thanks again for all of your advice.

If you are getting the sub categories upon selecting the main categories, why don’t you just select those sub categories of selected main category? Something like this:

SELECT * FROM tbl_subcategory WHERE category_ID=SELECTED_MAIN_CAT_ID

However I would rather combine two tables in the a single table having a field to reference to the parent category.

i already suggested this to him and he has decided not to do it because of all the code he has written

I think another thread was moved from MySQL!

Edit: if possible, mentors to merge two threads because they are completely for the same problem.

Why post the same question twice?

Now I lost time helping you with something someone else already solved for you :nono: