title: PHP Display Array in HTML table
body: <p>I have the database and web server on separate machines, an array from a mysql query is passed to the web server and looks like so</p>
  
  <pre><code>Array (
  [user_id] =&gt; 1
  [username] =&gt; phillip
  [password] =&gt; 12345
  [email] =&gt; phillip@gmail.com
  [account_balance] =&gt; 100   )
  </code></pre>
  
  <p>If I print out this array in PHP using print_r($myArray); it shows in the web browser like so </p>
  
  <pre><code> Array ( [user_id] =&gt; 1 [username] =&gt; phillip [password] =&gt; 12345 [email] =&gt; phillip@gmail.com [account_balance] =&gt; 100 ) 
  </code></pre>
  
  <p>I want to create PHP code that will iterate this array and make columns for user_id, username, password, email, and account_balance and then display the results in rows.</p>
  
  <p>Here is my PHP code in a file display.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
     &lt;html&gt;
         &lt;head&gt;
             &lt;meta charset="UTF-8"&gt;
             &lt;title&gt;Page&lt;/title&gt;
         &lt;/head&gt;
         &lt;body&gt;
            &lt;table border="1"&gt;
  &lt;?php
   include(fileThatCallsDBServer.php);
   $myArray = getMYSQLArray(); //This calls a function located in the file in the include() and returns array
   print_r($myArray); //print the array for testing purposes
  
   //Create table to display array 
   $html = "&lt;table&gt;";
   foreach($myArray as $row) {
      $html .= "&lt;tr&gt;";
         foreach ($row as $cell) {
            $html .= "&lt;td&gt;" . $cell . "&lt;/td&gt;";
         }
         $html .= "&lt;/tr&gt;";
   }
   $html .= "&lt;/table&gt;";
   ?&gt;
  
         &lt;/body&gt;
  
   &lt;/html&gt;
  </code></pre>
  
  <p>However, nothing gets displayed when I look at the page on my browser. Ideas?</p>