Jump to content

Recommended Posts

I want to be able to count the amount of values that is grouped.

For example

User A has Item1

User A has Item1

User A Has Item1

 

after grouped it'd be like

User A has Item1 (x3)

 

the x3 is a value I need, wasn't sure to post this in php or sql, I know the Group by will effect counts and I'm not really counting how many times a Name Appears because User A might have Item2 or 3 or 10, I just need to count the number of times User A has the same Item multiple times.

 

Anyone know how to do this? Greatly appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/
Share on other sites

If you are querying for just one user, GROUP BY item would give you a count of the number if each different items for that one user. If you are querying for more than one user and you want a count per user, per item, use GROUP BY user, item

How do I get the variable of the group to output the number?

 

Atm I do something like: (this is by item, not user, but same principles)

$itemtrack = mysql_query("SELECT * FROM ". ITEMTRACK_DATABASE ." GROUP BY ". ITEMTRACK_DATABASE_ITEM ." ORDER BY ". ITEMTRACK_DATABASE_ITEM .""); 

 

this is then in a while mysql_fetch_array which will output the usual stuff.

 

How do I make a php variable like $amount = the total in a group specific to a user. (they'll be more than 1 user)

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.