我想在我的表中获取记录数量,但它会发出警告

时间:2013-12-12 09:49:16

标签: php

警告:mysql_num_rows()要求参数1为资源,在

中给出布尔值
mysql_connect("localhost","root","");
mysql_select_db("db_usr");
$data=mysql_query("select * from tbl_usr");
$count=mysql_num_rows($data);
echo $count;

7 个答案:

答案 0 :(得分:1)

尝试使用mysqli,因为不推荐使用mysql。

答案 1 :(得分:0)

如果有人正在阅读此页面并错过该部分,则可以快速回复结果:

$counter = mysql_query("SELECT COUNT(*) AS total FROM table");
$num = mysql_fetch_array($counter);
$count = $num["total"];
echo("$count");

答案 2 :(得分:0)

如果出现错误,

mysql_query返回false(布尔值)。

在继续之前,您可以检查查询是否正常。

if(!$data) //error;

答案 3 :(得分:0)

试试这个

$co=mysql_connect("localhost","root","");  
$con=mysql_select_db("db_usr",$co);  
$data=mysql_query("select * from tbl_usr");  
$count=mysql_num_rows($data);      
echo $count;

答案 4 :(得分:0)

试试这个

$Conn = mysqli_connect("localhost","root","","db_usr");
$data = mysqli_query($Conn , "select * from tbl_usr");
$count = mysqli_num_rows($data);
echo $count;

此致

Dhaval Pithva

答案 5 :(得分:0)

尝试mysql_error()。我认为你提供了错误的数据库名称或tbl名称

 mysql_connect("localhost","root","");
 mysql_select_db("db_usr") or die(mysql_error());
 $data = mysql_query("select * from tbl_usr") or die(mysql_error());
 $count = mysql_num_rows($data);
 echo $count;

答案 6 :(得分:0)

试试这个

 $con=mysqli_connect("localhost","root","");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
 $result = mysqli_query($con, "select * from tbl_usr");
$rowcount=mysqli_num_rows($result);
echo $rowcount;