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'
| '. Join (' |
', $ Head ).' |
'; Echo'
'; Foreach ($ head as $ v) echo'
| '. (Isset ($ res [$ v])? $ Res [$ v]: '').' | '; Echo'
';
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?