title: Mysql select query/ PHP function is generating an infinite loop
body: <p>I have a function that is meant to select data from a database to be displayed in a table. The function is generating an endless loop. How may I fix that?</p>
  
  <p>My code is below:</p>
  
  <pre><code>function view()
  {
      $db = new mysqli("localhost", "root", "", "blog");
      $sql = 'SELECT * FROM news';
      $result = $db-&gt;query($sql) or die($mysqli-&gt;error);
      return $result-&gt;fetch_assoc();
  }
  ?&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th scope="col"&gt;Title&lt;/th&gt;
      &lt;th scope="col"&gt;Slug&lt;/th&gt;
      &lt;th scope="col"&gt;Text&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php while($row = view()) { ?&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;?php echo $row['title']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['slug']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['text']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php } ?&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>Thanks.</p>