$sql = SELECT `chengji`,count(*)  AS count FROM `table` GROUP BY `chengji`
在php中把mysql_query($sql);的结果打印出来看看

解决方案 »

  1.   


    结果是Resource id #5
      

  2.   


    用mysql_fetch_array结果为Array ( [0] => 及格 [type] => 及格 [1] => 4 [count] => 4 )
      

  3.   

    while($row = mysql_fetch_array()){}
      

  4.   

    while($row = mysql_fetch_array()){}
    我明白了 这样和数据库中查询出的格式的一样的
    可是我想在页面中做一个固定的table 和数据库中的格式不一样
      

  5.   

    $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);
    可以得到类似这样的数组Array
    (
        [及格] => 4
        [不及格] => 1
        [良好] => 3
    )然后$res[''] = '数量';
    $head = array('', '不及格', '及格', '良好');
    echo '<table>';
    echo '<tr><th>' . join('</th><th>', $head) . '</th></tr>';
    echo '<tr>';
    foreach($head as $v) echo '<td>' . (isset($res[$v]) ? $res[$v] : '') . '</td>';
    echo '</tr></table>';
      

  6.   

    再问个小问题 怎么用date() 获取 当月  月初 和 月末 日期
      

  7.   

    <?php
    date_default_timezone_set("PRC");echo "当前月份是".date("m")."\n";
    echo "本月初日期是".date("m")."-01\n";
    echo "本月未日期是".date("m")."-".date("t")."\n";
    ?>