0

Done this hundred of times before but this one is really throwing me out. As you can see the $value is not converted to string; but the echo before $result .= outputs just fine as you can see in the log. The var_dump also looks fine to me. I also tried (string)$value. Can anyone shed some light ?

PHP CODE:

  if ($result = $query->get_result()) {

    while ($data = mysqli_fetch_assoc($result)) {
      foreach ($data as $key => $value) {
        var_dump($data);
        echo $value;
        $result .= "<div class='post modelVariant'>".$value."</div>";
      }
    }

  mysqli_close($MySQLi);
  } else {
  mysqli_close($MySQLi);
  }

CONSOLE LOG:

array(1) {
["model_variant"]=>
string(3) "9.0"
}

9.0

Recoverable fatal error: Object of class mysqli_result could not be converted to string

Dharman
  • 30,962
  • 25
  • 85
  • 135
Doer
  • 53
  • 1
  • 8

1 Answers1

2

You use variable $result both to concatenate string $result .= "<div class='post modelVariant'>".$value."</div>"; and for storing result from MySQL query $result = $query->get_result().

kgr
  • 779
  • 6
  • 8