简体   繁体   中英

Printing values from a foreach array in PHP

Hi below is part of a code I have in my programme.

      .......................... 
       foreach($_POST['delz'] as $delz)
       {
            $QR = "SELECT bname, bsku FROM brands WHERE id='$delz'";
            $rr= mysqli_query($db,$QR) or die ("SQL Error");
            $roV = mysqli_num_rows($rr);


       echo "<tr>
       <td class='sc_five'>
       $rr ";
              .........

When I attempt to print the values of $rr I get an error saying Object of class mysqli_result could not be converted to string in C:\\xam........ Can someone tell me where have I gone wrong and how do I adjust myself?

EDIT:

I've got the connection as follows;

include ('../../connection/index.php'); 

Try this:

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");
        $roV = mysqli_num_rows($rr);
        $r=$rr->fetch_assoc();
            foreach ($r as $rr)
                echo "<tr><td class='sc_five'>".$rr['bname']." ".$rr['bsku'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM