0
I have a table subcategorias
and I have another anuncios
, where it has the id of the subcategory. I need to search all subcategories and return together, by subcategory, the amount of ads it has, the problem is that I’m already generating subcategories with another loop from another table. How could I do that?
SELECT * from `subcategorias`
LEFT JOIN `anuncios` ON `subcategorias`.`id_subcategoria` = `anuncios`.`id_anuncio`
WHERE `anuncios`.`status` = 1;
So, basically, I have to list all the subcategories, and together, do a Count of how many active ads each has for later I play this loop on the page
if advertising has the id of the subcategory, why not ON subcategory.id = ads.id_subcategory ?
– Victor
Because subcategories are generated dynamically through the categories page. By the category ID, the loop is formed with the subcategory menu. In this menu are listed the names of the subcategories and the amount of ads each has, however, even if the subcategory does not contain an ad, the loop should continue to run to bring up all subcategories but so far, what I did was bring only subcategories that contain ads.
– user60485