title: How to put mysqli while result into one variable and echo it in html
body: <p>How do I put ALL the while result in mysqli select into one variable and echo into the html document?</p>
  
  <p>Code are based on W3school
  PHP</p>
  
  <pre><code>    $sql = "SELECT firstname, lastname FROM MyGuests";
      $result = $conn-&gt;query($sql);
  
      if ($result-&gt;num_rows &gt; 0) {
          // output data of each row
          while($row = $result-&gt;fetch_assoc()) {
  //previously it was  echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
  ";
  $parsedcontent = '&lt;div class="col-md-4"&gt;'.$row["firstname"].'&lt;/div&gt;&lt;div class="col-md-4"&gt;'.$row["lastname"].'&lt;/div&gt;';
          }
      } else {
          echo "0 results";
      }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;?php echo $parsedcontent; ?&gt;
  &lt;/div&gt;
  </code></pre>