title: PHP mysqli query result echo with foreach loop
body: <p>in my last project I used <code>foreach</code> loop to assign to every mysqli result a variable, like <code>$r-&gt;mydata</code>, but I formatted my pc accidentally, so I lost my core file and I can't remember how exactly I did that. I remember that I did something like this</p>
  
  <pre><code>$result = $db-&gt;query("SELECT * FROM data");
  if($result-&gt;num_rows){
      while ($row = $result-&gt;fetch_object()) {
          foreach ($row as $r){
              $row[] = $r;
          }
      }
  }
  </code></pre>
  
  <p>And I can access the result from outside the while loop like this:</p>
  
  <pre><code>&lt;?php echo $r-&gt;mydata ?&gt;
  </code></pre>
  
  <p>Can anyone edit my code so it will work like before?</p>