Page 1 of 1

MYSQL SELECT COUNT displayed in PHP

Posted: Thu Jan 06, 2005 3:05 pm
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

Posted: Thu Jan 06, 2005 3:09 pm
by Weirdan
Robert, do not crosspost

Posted: Thu Jan 06, 2005 3:41 pm
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>';

Posted: Thu Jan 06, 2005 8:03 pm
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

Posted: Thu Jan 06, 2005 8:06 pm
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.