title: PHP while loop output to HTML
body: <p>I have below DIV in html</p>
  
  <pre><code>&lt;div class="result1" id="result1" name="result1"  &gt;
      &lt;table&gt;
          &lt;tr&gt;
               &lt;th&gt; Date&lt;/th&gt;
               &lt;th&gt; Bank&lt;/th&gt;
               &lt;th&gt; Type&lt;/th&gt;
               &lt;th&gt; Income Category&lt;/th&gt;
               &lt;th&gt; Expense Category&lt;/th&gt;
               &lt;th&gt; Expense Sub Category&lt;/th&gt;
               &lt;th&gt; Amount&lt;/th&gt;
          &lt;/tr&gt;
          &lt;?php echo $out; ?&gt;
      &lt;/table&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p>and I am trying to display below PHP loop output inside <code>result1</code></p>
  
  <pre><code>while($row = $result -&gt;fetch_assoc()) {
      $out = "&lt;tr&gt;
          &lt;td&gt;".$row["date"]."&lt;/td&gt;
          &lt;td&gt;".$row["select_bank"]."&lt;/td&gt;
          &lt;td&gt;".$row["entry_type"]."&lt;/td&gt;
          &lt;td&gt;".$row["income_cat"]."&lt;/td&gt;
          &lt;td&gt;".$row["expense_cat"]."&lt;/td&gt;
          &lt;td&gt;".$row["expense_cat_sub"]."&lt;/td&gt;
          &lt;td&gt;".$row["amount"]."&lt;/td&gt;
      &lt;/tr&gt;";
  }
  </code></pre>
  
  <p>The problem is I am getting only the last row of the loop inside HTML, not all of them.</p>
  
  <p>I tried below method to echo the div id via php:</p>
  
  <pre><code>echo "&lt;div class=\"output1\"&gt;$out&lt;/div&gt;";
  </code></pre>
  
  <p>Problem with above method is output is showing at top of the page, not inside <code>output1</code> div. I would like show the result inside <code>output1</code> at the correct location.  How can I achieve it?</p>