mytable:
id name value prob
1 andy 100 0
2 luna 0 1
3 joe 0 0
4 linda 50 3
5 rob 25 2
6 steph 100 0
7 rudy 0 0
<?php
$con = mysql_connect('localhost','root','') or die(mysql_error());
$db = mysql_select_db('mydb') or die (mysql_error());
$sql = "SELECT Count(*) AS total,
(SELECT Count(*) FROM mytable WHERE mytable.value=100) AS filled,
(SELECT Count(*) FROM mytable WHERE mytable.prob>=1) AS problems
FROM mytable";
$query = mysql_query( $sql ) or die(mysql_error());
while( $rows = mysql_fetch_array( $query ) ){
$totals=$rows['total'];
$fills=$rows['filled'];
$probs=$rows['problems'];
?>
TOTAL <?php echo $totals; ?>
CLEARED <?php echo $fills; ?>
PROBLEMS <?php echo $probs; ?>
<?php } ?>
使用navicat生成查询..结果是正确的,但是当我在我的视图中编写代码时:
TOTAL 7
CLEARED 0
PROBLEMS 0
需要这样的结果:
TOTAL 7
CLEARED 2
PROBLEMS 3