How the GROUP by statement uses PHP output to class
There are ' Chengji ' fields in database Tabel three values for failing to pass
The page shows the statistics of three values
I use
SELECT ' Chengji ', COUNT (*) from ' table ' GROUP by ' Chengji '
In MySQL can come out but how to display in the PHP file that
The page looks like
| Fail | Pass | Good |
Quantity | | | |
------Solution--------------------
$sql = SELECT ' Chengji ', COUNT (*) As CountFrom ' table ' GROUP by ' Chengji '
Print out the results of mysql_query ($sql) in PHP to see
------Solution--------------------
$sql = SELECT ' Chengji ', COUNT (*) as count from ' table ' GROUP by ' Chengji ';
$rs = mysql_query ($sql);
while ($row = Mysql_fetch_assoc ($rs)) {
$res [$row [' Chengji ']] = $row [' count '];
}
Print_r ($res);
You can get an array like this.
Array
(
[Pass] = 4
[Fail] = 1
[Good] = 3
)
And then
$res ['] = ' quantity ';
$head = Array (', ' fail ', ' pass ', ' good ');
Echo '
'; Echo '
'. Join (' |
', $head). ' |
'; Echo '
'; foreach ($head as $v) echo '
' . (Isset ($res [$v])? $res [$v]: '). ' | '; Echo '
';
------Solution--------------------
Reference:
Ask a small question again how to get the month and month date with date ()
Date_default_timezone_set ("PRC");
echo "Current month is". Date ("M"). " \ n ";
echo "Date earlier this month is". Date ("M"). " -01\n ";
echo "No date this month is". Date ("M"). " -". Date (" T ")." \ n ";
?>