在PHP中打印foreach数组中的值

时间:2013-05-05 05:43:21

标签: php

下面是我程序中代码的一部分。

      .......................... 
       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 ";
              .........

当我尝试打印$rr的值时,我收到错误提示Object of class mysqli_result could not be converted to string in C:\xam........有人可以告诉我哪里出错了,我该如何调整自己?

修改

我的连接如下;

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

1 个答案:

答案 0 :(得分:1)

试试这个:

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