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
MYSQL SELECT COUNT displayed in PHP
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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>';