title: PHP echoing MySQL data into HTML table
body: <p>So I'm trying to make a HTML table that gets data from a MySQL database and outputs it to the user. I'm doing so with PHP, which I'm extremely new to, so please excuse my <a href="https://stackoverflow.com/a/31716438/5172019">messy code</a>!</p>
  
  <p>The code that I'm using is: <em>braces for storm of "your code is awful!"</em></p>
  
  <pre><code>&lt;table class="table table-striped table-hover "&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;#&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
          &lt;th&gt;Reward&lt;/th&gt;
          &lt;th&gt;Column heading&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;?php
          $con = mysql_connect("localhost", "notarealuser", 'notmypassword');
          for ($i = 1; $i &lt;= 20; $i++) {
              $items = ($mysqli-&gt;query("SELECT id FROM `items` WHERE id = $i"));
              echo ("&lt;tr&gt;");
              echo ("
                  &lt;td&gt;
                  while ($db_field = mysqli_fetch_assoc($items)) {
                      print $db_field['id'];
                  }&lt;/td&gt;");
              $items = ($mysqli-&gt;query("SELECT name FROM `items` WHERE id = $i"));
              echo ("
                  &lt;td&gt;
                  while ($db_field = mysqli_fetch_assoc($items)) {
                      print $db_field['name'];
                  }&lt;/td&gt;");
              $items = ($mysqli-&gt;query("SELECT descrip FROM `items` WHERE id = $i"));
              echo ("
                  &lt;td&gt;
                  while ($db_field = mysqli_fetch_assoc($items)) {
                      print $db_field['descrip'];
                  }&lt;/td&gt;");
              $items = ($mysqli-&gt;query("SELECT reward FROM `items` WHERE id = $i"));
              echo ("
                  &lt;td&gt;
                  while ($db_field = mysqli_fetch_assoc($items)) {
                      print $db_field['reward'];
                  }&lt;/td&gt;");
              $items = ($mysqli-&gt;query("SELECT img FROM `items` WHERE id = $i"));
              echo ("
                  &lt;td&gt;
                  while ($db_field = mysqli_fetch_assoc($items)) {
                      print $db_field['img'];
                  }&lt;/td&gt;");
              echo ("&lt;/tr&gt;");
          }
      ?&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>However, this code is not working - it simply causes the page to output an immediate 500 Internal Server Error. IIS logs show it as a 500:0 - generic ISE. Any ideas?</p>