The following example selects the same data as the example above, but will display the data in an HTML table:
< ?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo " < tr > <>Firstname< /th > <>Lastname< /th > < /tr >";
while($row = mysql_fetch_array($result)) { echo "<>"; echo "<>" . $row['FirstName'] . ""; echo "<>" . $row['LastName'] . "< /td >"; echo "< /tr >"; } echo " ";
mysql_close($con); ? > |
The output of the code above will be:
Firstname | Lastname |
Glenn | Quagmire |
Peter | Griffin |