I have categories currently in my HTML code as follows:
<ul>
<li>Category 1: ($Count)</li>
<li>Category 2: ($Count)</li>
<li>Category 3: ($Count)</li>
</ul>
I want list the count of number of elements each category contain. i could get the count a of category using following SQL syntax:
SELECT COUNT(element) FROM category WHERE cid = 1
However, I don’t know how to bind this up to each category in the HTML code.
I can only think of one other way of implementing this: make the category name dynamic by storing it also in the database, then select all the categories with count.
I think you it will be better if you could store category name in database. If you store Category name in database like
Then you could query database like:
If you don’t store the Category Name in db, another possibility is that if your cid 1 is same as category 1 and so on then you can do.
Provided the $result is in array in order then you can do
But i recommend you to use first one.
Hope this helps 🙂