Jump to content

Count function


Smee

Recommended Posts

Hey,

 

I have been playing around with a count function and have it nearly working how i want it to but cant figure out what is going wrong. The code is returning these results:

 

There are 11 11 supporters.

There are 9 9 supporters.

There are 2 2 supporters.

There are 2 2 supporters.

There are 1 1 supporters.

There are 1 1 supporters.

 

The second number(s) should be the names of teams but i can't seem to get the names to show. The reason for this is because of the duplication of . $row['team_supported'] ." but if i have it like . $row['COUNT(team_supported)'] ." i get an error of undefined variable.

 

Anyway here is what i have done so far.

 

<?php

$query = "SELECT team_supported, COUNT(team_supported) AS team_supported FROM users GROUP BY team_supported ORDER BY team_supported DESC LIMIT 6"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
echo "There are ". $row['team_supported'] ." ". $row['team_supported'] ." supporters.";
echo "<br />";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/204110-count-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.