Hope this may help you.
You should have two tables - 1. category(id, name)
2. items(id, name, catid)
. I just have taken minimum fields but you may add. catid
is the reference of category id
in the items table.
Your query should be like -
SELECT c.name as Category, COUNT(i.id) as Items
FROM category as c LEFT OUTER JOIN items as i ON (c.id= i.catid)
GROUP BY c.id ORDER BY c.name