D Karolis
D Karolis

Reputation: 51

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'); 

Upvotes: 0

Views: 72

Answers (1)

Dave Chen
Dave Chen

Reputation: 10975

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'];

Upvotes: 1

Related Questions