mysql_fetch_row($sql)会得到二维数组?

来源:百度知道 编辑:UC知道 时间:2024/05/24 20:17:18
$query="select count(id) from content";
$result = @mysql_query( $query,$conn);
while($row=@mysql_fetch_row($result))
{
$output= $row;
}
@mysql_free_result($result);
@mysql_close($conn);
有个地方写错了!就是while循环中,应该是这样的
$output[]=$row;
是这样的!

mysql_fetch_row($sql)只能得到一维数组,不可能得到二维数组的,一次fetch只能得到查询语句的一行,通过while的循环可以得到所有查询结果,把这些结果串起来能得到二维数组,但是需要自己写程序来串。

你的程序是SELECT COUNT(*)语句,只返回一行数据,你无需用while循环,直接把while循环前后括号去掉,加上分号即可,如:

$query="select count(id) from content";
$result = @mysql_query( $query,$conn);
$row=@mysql_fetch_row($result);
$output= $row;
@mysql_free_result($result);
@mysql_close($conn);