title: Printing mySQL table to webpage
body: <p>I'm very new to php and I want to use it to print out the contents of my mySQL table to a web page. So far I have the 'connect to database' part, but I'm really stuck as to how to actually print out the data, preferably in a HTML table.</p>
  
  <p>My PHP:</p>
  
  <pre><code>&lt;?php    
  
  $username="root";
  $password="password";
  $database="posts";
  mysql_connect("localhost",$username,$password);
  mysql_select_db($database) or die( "Unable to select database");
  
  $query= "SELECT * FROM input";
  
  $result=mysql_query($query);
  
  mysql_close();
  
  ?&gt;
  </code></pre>
  
  <p>My HTML for my web page:</p>
  
  <pre><code>&lt;!doctype html&gt;
  
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;link rel="stylesheet" href="css/viewstyle.css"&gt;
    &lt;title&gt;Database View&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1&gt; Database View Page &lt;/h1&gt;
      &lt;p&gt; Here you can view the Database &lt;/p&gt;
      &lt;script src="display.php"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks for your time.</p>
  
  <p>EDITED:</p>
  
  <pre><code>&lt;!doctype html&gt;
  
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;link rel="stylesheet" href="css/viewstyle.css"&gt;
    &lt;title&gt;Database View&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1&gt; Database View Page &lt;/h1&gt;
      &lt;p&gt; Here you can view the Database &lt;/p&gt;
  
  
      &lt;?php
  
          $username="root";
          $password="password";
          $database="posts";
          mysql_connect("localhost",$username,$password);
          mysql_select_db($database) or die( "Unable to select database");
  
          $query= "SELECT * FROM input";
  
          $result=mysql_query($query);
  
          echo "&lt;table border='1' cellpadding='10'&gt;";
          echo "&lt;tr&gt;&lt;th&gt;First name&lt;/th&gt;&lt;th&gt;Last name&lt;/th&gt;&lt;th&gt;Age&lt;/th&gt;&lt;/tr&gt;";
  
          while($row = mysql_fetch_array($result))
           {
            echo '&lt;td&gt;' . $row['firstname'] . '&lt;/td&gt;';
            echo '&lt;td&gt;' . $row['surname'] . '&lt;/td&gt;';
            echo '&lt;td&gt;' . $row['age'] . '&lt;/td&gt;';
            echo "&lt;/tr&gt;"; 
            }
           echo "&lt;/table&gt;";
  
                       mysql_close();
  
      ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When my page loads it now shows:</p>
  
  <p>" "; echo " Sample Sample Description"; while($row = mysql_fetch_array($result)) { echo '' . $row['firstname'] . ''; echo '' . $row['surname'] . ''; echo '' . $row['age'] . ''; echo ""; } echo ""; ?> mysql_close(); "</p>
  
  <p>As text on my webpage.</p>