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
Share on other sites

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.