0

Hi can someone help me understand the following error? it says

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, array given in C:\xampp\htdocs\docs\scheme\master\index.php on line 412

and my code goes as follows;

.....
       foreach($_POST['delz'] as $delz)
       {
   $delz=mysqli_real_escape_string($db,$delz);
    $QR = "SELECT bname, bsku FROM brands WHERE id='$delz'";
    $rr = mysqli_query($db,$QR) or die ("SQL Error");
    $rr = $rr->fetch_assoc();
    $roV = mysqli_num_rows($rr); //line 412 reads as this
    echo "<tr><td class='sc_five'>".$rr['bname']." ".$rr['bsku']; 

....code continues

Appreciate your help.

Thank you!

4

1 回答 1

3

切换这 2 行:

$rr = $rr->fetch_assoc();
$roV = mysqli_num_rows($rr);

$roV = mysqli_num_rows($rr);
$rr = $rr->fetch_assoc();

mysqli_fetch_assoc()调用后$rr不引用实际的 MySQLi 结果资源,而是其第一行的数组表示,它丢失了所有其他周围信息,例如返回的行数。这就是为什么mysql_num_rows()无法确认$rr为有效的 MySQLi 结果资源的原因。

于 2013-05-05T14:08:03.997 回答