contactTable.php

Source of contactTable.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    <title>contactTable.php</title>
    <style type = "text/css">
      table, th, td {
        border: 1px solid black;
      }      
    </style>
  </head>

  <body>
    <h1>My Contacts</h1>
  <?php
$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("xfd");
$sql = "SELECT * FROM contact";
$result = mysql_query($sql, $conn);

print "  <table> \n";

//get field names first
print "      <tr> \n";
while ($field = mysql_fetch_field($result)){
  print "        <th>$field->name</th> \n";
} // end while
print "      </tr> \n";

while ($row = mysql_fetch_assoc($result)){
  print "      <tr> \n";
  foreach ($row as $name => $value){
    print "        <td>$value</td> \n";    
  } // end foreach
  $count++;
  print "      </tr> \n";

} // end while loop

print "    </table> \n";
  
  ?>
  </body>
</html>