php 中count()函数的用法

来源:百度知道 编辑:UC知道 时间:2024/05/27 11:19:41
想在mysql数据库中写入东西,但是名字不能重复,我用了
$count ="select count( name ) from test where name='$name'";
$result= mysql_query("$count");
但是,$result的值始终为0。
想问一下,如何保存count函数返回的值?
非常感谢

你的mysql错了
首先得连接MYSQL和数据库。
你可以找找例子。
假设链接为$con
$result= mysql_query($con,$count);
这个只是查询,还不是获取数据
应该再来个函数,$row=mysql_fetch_array($result)
这个值就是$row[0]

$count ="select count( name ) from test where name='$name'";
$result= mysql_query($count);
$rows=mysql_fetch_row($result);
echo $rows[0];