MYSQL SELECT COUNT displayed in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robgo777
Forum Newbie
Posts: 3
Joined: Thu Jan 06, 2005 3:05 pm

MYSQL SELECT COUNT displayed in PHP

Post by robgo777 »

I am trying to view data statistics from my MySQL database. I have the SQL query just fine, but I can't seem to display the information with php:

SELECT gender, COUNT(gender) AS number FROM links GROUP BY gender ORDER BY gender

The Result should be:

gender number

Female 15934
Male 19707

This works fine with SQL, but I can't seem to get it to echo this information in php to be displayed in a browser. I also need to execute multiple SELECT queries to get all statistics in this links table at once.

If you could help. then I would appreciate it. I allready searched the forums for an answer, but no luck. Only code to dislplay the number of rows, but that is not what I want.

Also, if you know how this can also be displayed graphically, then that would be a difinate plus.

v/r,

Robert
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Robert, do not crosspost
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I know we've talked about this...

Code: Select all

# assume $query is the result of the query call
$first = true;
$output = '<table>';
while($row = mysql_fetch_assoc($query))
{
  if( $first ) $output .= '<tr><td>' . join('</td><td>', array_keys($row)) . '</td></tr>' . "\n";
  $first = false;
  $output .= '<tr><td>' . join('</td><td>',array_values($row)) . '</td></tr>' . "\n";
}
if( $first )
  $output .= '<tr><td>No entries</td></tr>';
$output .= '</table>';
robgo777
Forum Newbie
Posts: 3
Joined: Thu Jan 06, 2005 3:05 pm

Post by robgo777 »

Thanks Feyd for the reply...Weirdan, I don't know what you are talking about crossposting. how about you not respond to threads with worthless advice.

Anyways, Feyd, how exactly does:
SELECT gender, COUNT(gender) AS number FROM links GROUP BY gender ORDER BY gender

Fit into your php?

Thanks,

Robert
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read the first line.



crosspost: In electronic fora (e.g., e-mail, newsgroups, and electronic bulletin boards), to send a message to more than one forum, where it might be of interest to a wider audience than is reached with a single forum.
Post Reply