rockonxox Posted December 1, 2005 Share Posted December 1, 2005 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/2964-counting-rows-based-on-a-column-value/ Share on other sites More sharing options...
ryanlwh Posted December 1, 2005 Share Posted December 1, 2005 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--] Quote Link to comment https://forums.phpfreaks.com/topic/2964-counting-rows-based-on-a-column-value/#findComment-9971 Share on other sites More sharing options...
rockonxox Posted December 1, 2005 Author Share Posted December 1, 2005 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... Quote Link to comment https://forums.phpfreaks.com/topic/2964-counting-rows-based-on-a-column-value/#findComment-9972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.