这句sql语句
select count(*) from ffed where Cwtype = '临时车位'
我放到数据库里面执行结果是2但用php获取
$sql2 ="select count(*) from ffed where Cwtype = '临时车位'";
$linshi=mysql_query($sql2);$linshi的值为Resource id #4请问应该如何获取

解决方案 »

  1.   

    $sql2 ="select count(*) as count from ffed where Cwtype = '临时车位'";
    $linshi=mysql_query($sql2);
    $row = mysql_fetch_assoc($linshi);
    echo $row['count'];//就是统计数字。也可以用mysql_num_rows()函数
      

  2.   

    $sql2 ="select count(*) as count from ffed where Cwtype = '临时车位'";
    $linshi=mysql_query($sql2);
    $row = mysql_fetch_object($linshi);//返回对象数组!楼上的方法取法也一样的道理!
    echo $row->count;//count就是统计数字。也可以用mysql_num_rows()函数!核心还是SQL语句。你没有as一下。
    当然不用的话就直接用mysql_num_rows()取值
      

  3.   


    $countsql = "select count(*) as count from ffed where Cwtype = '临时车位'";
    $count = $this->db->getOne($countsql);
    echo $count;              
      

  4.   


     function getOne($sql)
        {
            if (is_resource($sql)) {
                $res = $sql;
            } else {
                $res = $this->execute($sql);
            }
            $row = pg_fetch_row($res);
            pg_free_result($res);
            return isset($row[0]) ? $row[0] : null;
        }
      

  5.   

    $sql2 ="select count(*) from ffed where Cwtype = '临时车位'";
    $linshi=mysql_query($sql2);
    $arr = mysql_fetch_array($linshi);
    echo $arr[0];