Here we give an example of the PHP code that will read data out of a MySQL database and present it in a nice tabular format in HTML.
Assuming we have the following MySQL table:
Table Employee
Name | Salary |
Lisa | 40000 |
Alice | 45000 |
Janine | 60000 |
$link = @mysql_pconnect("localhost","cat","dog") or exit(); mysql_select_db("myinfo") or exit(); print "<p>Employee Information"; print "<p><table border=1><tr><td>Employee Name</td><td>Salary Amount</td></tr>"; $result = mysql_query("select name, salary from Employee"); while ($row=mysql_fetch_row($result)) { print "<tr><td>" . $row[0] . "</td><td>" . $row[1] . "</td></tr>"; } print "</table>"; |
Employee Information
|
$link = @mysql_pconnect("localhost","cat","dog") or exit(); mysql_select_db("myinfo") or exit(); |
$result = mysql_query("select name, salary from Employee"); |
while ($row=mysql_fetch_row($result)) { print "<tr><td>" . $row[0] . "</td><td>" . $row[1] . "</td></tr>"; } |
Previous Page->PHP-Redirect || Next Page->Tutorial-string-functions