Jump to content

Recommended Posts

The site I am using this for is a secret santa database for a web group I'm a part of. Everything works fine, but I'm noticing that many members have more "gift items" than others.

 

The table for gifts that have been sent (which I am wanting to count), records many presents for each individual, which is why I need to count the rows based on the column of "hfname". So in short, I want to count the rows, using the column hfname, and group them based on if the name shows up in 0, 1-3, 5-10, or 10+ rows.

 

I want to set up the gift analysis like so:

Members with no gifts

(insert php to count hfname values returning 0 rows)

 

Members with 1-3 gifts

(insert php to count hfname values returning 1-3 rows)

 

Members with 5-10 gifts

(insert php to count hfname values returning 5-10 rows)

 

Members with over 10 gifts

(insert php to count hfname values returning >10 rows)

 

---------------

 

This is really the first site I've done using databases, so it's more a learning tool than anything of real use, at least not unless it's the holidays =)

Link to comment
https://forums.phpfreaks.com/topic/2964-counting-rows-based-on-a-column-value/
Share on other sites

Not sure whether this is what you want

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname='0' [!--sql2--][/div][!--sql3--]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname BETWEEN '1' AND '3' [!--sql2--][/div][!--sql3--]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname>10 [!--sql2--][/div][!--sql3--]

Not sure if that will work. Hfname is just a column fieldname... I want to be able to get results like this:

 

Member has 0 presents

Kelly

Alia

Candymara

 

Member has 1-3 presents

Tigerlily

Dana

KirstinVP

 

Members has 5-10 presents

JillianVP

 

Member has 10+ presents

None

 

 

So I'd need to count rows based on how many times a value occurs in the hfname column...

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.