How the GROUP by statement uses PHP output to class

Source: Internet
Author: User
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 ' '; Echo ' '; foreach ($head as $v) echo ' '; Echo '
'. Join (' ', $head). '
' . (Isset ($res [$v])? $res [$v]: '). '
';

------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 ";
?>
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.