sql错误警告:mysqli\u num\u rows()期望参数1是mysqli\u result,给定布尔值

yrwegjxp  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(279)

这个问题在这里已经有答案了

mysql\u fetch\u array()/mysql\u fetch\u assoc()/mysql\u fetch\u row()/mysql\u num\u rows等…期望参数1是资源(31个答案)
两年前关门了。
请帮我纠正这个错误。当我试图查看收件箱消息时,它会通过错误
警告:mysqli\u num\u rows()期望参数1是mysqli\u result,给定布尔值
因为它来自$req1 mysql查询。我认为这个小组有问题,但不确定。这是密码。

$req1 = mysqli_query($con, 'select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc');
$req2 = mysqli_query($con, 'select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc');
?>
This is the list of your messages:<br />
<a href="new_pm.php" class="link_new_pm">New PM</a><br />
<h3>Unread Messages(<?php echo intval(mysqli_num_rows($req1)); ?>):</h3>
mwg9r5ms

mwg9r5ms1#

mysqli_query 可以返回: mysqli_result 如果查询有 SELECT,SHOW,DESCRIBE,EXPLAIN 布尔值 true 对于所有其他查询
布尔值 false 如果失败
您需要使用if语句来处理它,检查它是否为布尔值,如果不是,则进行编码。 if (is_bool($req1) === false) { echo intval(mysqli_num_rows($req1)); } 还要测试您的查询,以确保它确实可以返回任何mysqli\u结果

相关问题