Jump to content

Recommended Posts

Hi,

 

Seen this so many times, but not sure exactly how it is done, and what is the right/wrong way:

 

For example:

 

CAT NAME (No.Of Items with that Category_id)

 

Category 1 (2)

Category 2 (12)

Category 3 (4)

Category 4 (168)

Category 5 (19)

 

How would one count the number of items within a category?

 

SELECT Cat_Name,Cat_QTY FROM CAT_TABLE

 

Where Cat_QTY is the number of items in ITEM_TABLE with category_id='x'.

 

Method 1:

When a new item is added or removed, the Cat_QTY is updated accordingly?

 

So, I am adding an Item, I get the Cat_QTY value and increment it by one and then update hte CAT_TABLE. Seems long winded.

 

Method 2:

Or would there be a script running in the background to determine the number if items in each category?

It would count all items in the item table with category_id='1' and then updating the category table accordingly for each category_id.

 

---------

 

I have tried search for this answer but I don't know what to search for "Summary table count"? The results do not bering back any relating info.

 

Thanks in advance,

Jamie.

 

 

Link to comment
https://forums.phpfreaks.com/topic/80766-solved-category-count-listing/
Share on other sites

Thank you for the prompt reply.

 

If you have 100 different categories, would that be ok in terms of processing required? Would it not be to intensive for the page loading, as well as other request made? I am not sure what counts as an intensive ODBC request.

 

Thanks agian.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.