mikeabe Posted November 19, 2008 Share Posted November 19, 2008 Can you help me with this? When i run this SQL command in phpMyAdmin: select student, count(student) from incoming group by student; Some kids names are counted correctly, others are shown twice. For example: 2 Angel Cesar 3 Angel Cesar Why would I not get: 5 Angel Cesar All the names are fed to Mysql from a php web form drop-down list, so there isn't any possibility of the names being spelled differently. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/ Share on other sites More sharing options...
revraz Posted November 19, 2008 Share Posted November 19, 2008 Does this work? SELECT count(*), student FROM incoming GROUP BY student; Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693534 Share on other sites More sharing options...
mikeabe Posted November 19, 2008 Author Share Posted November 19, 2008 Thanks for the response. I copied and pasted your code into Mysql, but i got the same result as before. Wierd how it's working. Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693557 Share on other sites More sharing options...
PFMaBiSmAd Posted November 19, 2008 Share Posted November 19, 2008 You probably have some white-space before or after the names. You would need to dump the data and examine it or check what the length is. If you do have some white-space, it is probably due to a coding error when the names were entered or when they are being put into the form. Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693565 Share on other sites More sharing options...
mikeabe Posted November 19, 2008 Author Share Posted November 19, 2008 Thanks. I'll check that out and let you know what i find. Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693590 Share on other sites More sharing options...
xtopolis Posted November 19, 2008 Share Posted November 19, 2008 It looks like he's trying to SUM() a column, not count the affected rows if he expects the result of 5 from his first post? Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693606 Share on other sites More sharing options...
revraz Posted November 19, 2008 Share Posted November 19, 2008 SUM adds the values in the fields, not how many iterations there are. What he is saying is that it shows 2 Angels and 3 Angels instead of 5 Angels, which means the Values are different somehow. Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693691 Share on other sites More sharing options...
mikeabe Posted November 19, 2008 Author Share Posted November 19, 2008 This is what's going on: The teachers submit tardies with a php/html web form. The data is sent to mysql. I'm trying to make a form that will tell the teachers who is getting the most tardies. the web form they see looks something like this: tardies student 4 campa myrea 4 delgado juan 3 anguiano maria 1 gerardo jose 1 archuletta david kids are ordered by tardies. So campa myrea has 4 tardies, and so on. And the teacher can see her individual tardies with dates, etc. on another form. the form works fine for MOST kids but some kids names look like this: 2 ramirez jennifer 2 ramirez jennifer and her name should be 4 ramirez jennifer I'm in the process of dumping data and submitting it again to see what happens. This is an intranet. I host everything from my computer. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693695 Share on other sites More sharing options...
revraz Posted November 19, 2008 Share Posted November 19, 2008 The best way to do this is use an ID for the students, then count the IDs instead. This will ensure there is only 1 name per ID. Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-693701 Share on other sites More sharing options...
mikeabe Posted November 20, 2008 Author Share Posted November 20, 2008 I'll try that. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/133342-mysql-count-doesnt-add-all-names/#findComment-694305 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.