Question

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!

Was it helpful?

Solution

Switch those 2 line:

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

to

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

After the mysqli_fetch_assoc() call $rr does not reference the actual MySQLi result resource, but an array representation of its first row, which hast lost all other surrounding information like, e.g., the count of rows returned. That is why mysql_num_rows() fails to acknowledge $rr as a valid MySQLi result resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top