How to use the php output for the GROUPBY statement?-php Tutorial

Source: Internet
Author: User
How to use the php output in the GROUPBY statement? in the tabel database, the content of the 'chengji 'field is good for failing.
The statistics of the three values are displayed on the page.
I use
SELECT `chengji`,count(*) FROM `table` GROUP BY `chengji`

In Mysql, how can I display it in the PHP file?

The page looks like
| Fail | pass | good |
Quantity |


Reply to discussion (solution)

$ SQL = SELECT 'chengji', count (*) AS count FROM 'table' GROUP BY 'chengji'
Print out the mysql_query ($ SQL); result in php.

$ SQL = SELECT 'chengji', count (*) AS count FROM 'table' GROUP BY 'chengji'
Print out the mysql_query ($ SQL); result in php.

The result is Resource id #5.

$ SQL = SELECT 'chengji', count (*) AS count FROM 'table' GROUP BY 'chengji'
Print out the mysql_query ($ SQL); result in php.

Use mysql_fetch_array

The result is Array ([0] => pass [type] => pass [1] => 4 [count] => 4)

Use mysql_fetch_array
The result is Array ([0] => pass [type] => pass [1] => 4 [count] => 4)
While ($ row = mysql_fetch_array ()){}


Use mysql_fetch_array
The result is Array ([0] => pass [type] => pass [1] => 4 [count] => 4)
While ($ row = mysql_fetch_array ()){}
I understand that the format is the same as that found in the database.
However, I want to make a fixed table on the page and the format in the database is different.

$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)

Then
$ Res [''] = 'quantity'; $ head = array ('', 'failed', 'pass', 'good'); echo'
 
 
  
  
'; Echo'
  
  '; Echo' 
   
     '; Foreach ($ head as $ v) echo' 
    '; Echo' 
   
'. Join (' ', $ Head ).'
'. (Isset ($ res [$ v])? $ Res [$ v]: '').'
';

How can I use date () to obtain the start and end dates of the current month?

How can I use date () to obtain the start and end dates of the current month?

 

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.