您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何查询返回记录数

2025/12/25 16:51:26发布23次查看
方法:1、使用mysql_num_rows函数,语法“mysql_num_rows(结果集)”;2、使用mysql_query函数执行“count(*)”查询,再使用mysql_fetch_row函数从结果集中取出数字数组。
本教程操作环境:windows7系统、php7.1版,dell g3电脑
php查询语句,有两种方法获得查询的总记录数。
mysqli 面向过程的方式
$sql = "select id, firstname, lastname from myguests";$result = mysqli_query($conn, $sql); num_rows=mysqli_num_rows($result);
一是使用mysql_num_rows函数,例子代码:
<?php$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("database", $link); $result = mysql_query("select * from table1", $link);$num_rows = mysql_num_rows($result);echo "$num_rows rows\n";?>
二是修改查询语句,使用count(*)作为查询内容,例子代码:
<?php$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("database", $link); $result = mysql_query("select count(*) from table1", $link);list($num_rows) = mysql_fetch_row($result);echo "$num_rows rows\n";?>
推荐:《2021年php面试题大汇总(收藏)》《php视频教程》
以上就是php如何查询返回记录数的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product