| 10 users per company
|
Gilead

msg:4400227 | 6:18 pm on Dec 21, 2011 (gmt 0) | I am trying to get a script to show which companies have more than one user per account number. It sort of works, but I wanted to see how many were actually being used. Code: $table_name=(USER); $query = "SELECT organization_title, email, account_number,COUNT(*) AS Count FROM $table_name GROUP BY account_number HAVING Count > 1; "; $result = mysql_query($query) or die("No Account Numbers Present!" . mysql_error()); echo "<table>"; while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td> Account Number: ' .$row["account_number"] .'</td>'; echo '<td> Organization: ' .$row["organization_title"] .'</td>'; echo '<td> Account Name:' .$row["account_name"] .'</td>'; echo '<td> Email: ' .$row["email"] .'</td>'; echo '<td>' .$row["COUNT({account_number})"] .'</td>'; echo '</tr>'; } echo "</table>"; Results: Notice: Undefined index: account_name in /path/to/file.php on line 37 Notice: Undefined index: COUNT({account_number}) in /path/to/file.php on line 39 Notice: Undefined index: account_name in /path/to/file.php on line 37 Notice: Undefined index: COUNT({account_number}) in /path/to/file.php on line 39 Notice: Undefined index: account_name in /path/to/file.php on line 37 Notice: Undefined index: COUNT({account_number}) in /path/to/file.php on line 39 Notice: Undefined index: account_name in /path/to/file.php on line 37 Notice: Undefined index: COUNT({account_number}) in /path/to/file.php on line 39 Account Number: 001A050i07agtt6IAAOrganization: Some Org Account Name:Email: email@domain.com Account Number: Hh7wf101Fp50isBcvqOrganization: Another Company Inc Account Name:Email: test@domain.com Account Number: qev0w31vMopohBi27mOrganization: Account Name:Email: testing@mydomain.com Account Number: qev0j31vM0ko1Bi27sOrganization: Account Name:Email: anotheremail@domain.com It's balking at COUNT. How is the best way to tell how many and echo that out? Thanks!
|
Dinkar

msg:4400265 | 8:45 pm on Dec 21, 2011 (gmt 0) | Would you please explain the query? SELECT organization_title, email, account_number,COUNT(*) AS Count FROM $table_name GROUP BY account_number HAVING Count > 1; I am little confuse about Count.
|
Dinkar

msg:4400275 | 9:40 pm on Dec 21, 2011 (gmt 0) | Alright, I gave 2nd look at your post and found that you are not fetching account_name in your select query but still trying to echo it: echo '<td> Account Name:' .$row["account_name"] .'</td>';
|
Gilead

msg:4400555 | 4:59 pm on Dec 22, 2011 (gmt 0) | Thank you! Hmm. That's not quite the output I was looking for. I was looking for a literal count of how many email addresses there were for the one account number. I've seen examples of the count array, but not sure how it relates to db access. Please help me understand. Thanks!
|
Habtom

msg:4400598 | 6:26 pm on Dec 22, 2011 (gmt 0) | This line: echo '<td>' .$row["COUNT({account_number})"] .'</td>'; should simply be this: echo '<td>' .$row["Count"] .'</td>';
|
Gilead

msg:4400611 | 7:15 pm on Dec 22, 2011 (gmt 0) | Ahhh! Thanks so much!
|
|
|