这句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.   


    上面给出了正确答案mysql_query执行了以后只是返回了一个mysql资源对象,要用mysql_fetch_assoc/mysql_fetch_rows等函数获取结果才可以
      

  3.   

    while($linshi = mysql_fetch_array($linshi)){
        print_r($linshi);
    }
      

  4.   

    $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函数输出也可以!echo mysql_num_rows($linshi); 
      

  5.   

    echo mssql_num_rows($linshi) ."<br>";//.获取记录集行数