First you need mysql installed to give you a database server (I called my server "mysql" when I installed it).
Then you need a database in the server (I called my database "test" when I created it).
Then you need a table in the database (I called the table "user", I created a column in the table called "id", and I inserted some rows into the table).
So now I can connect to server "mysql", select database "test", and run a query against table "user" to select every row, and display what's in column "id". The contents of "id" from each row is displayed in an HTML table:
<?php
// Connect to database server "mysql", select database "test"
$dbServerLink = mysql_connect("localhost", "mysql", "mysql") or die("Could not connect");
mysql_select_db("test") or die("Could not select database");
// Run SQL query
$query = "select u.id as ID from user u";
$resultResource = mysql_query($query) or die("Query failed: " . mysql_error());
// Start HTML table (drop out of php into normal HTML)
?>
<table border="1">
<th>ID</th>
<?
//Now read each row and put it in HTML table (back in php)
while ($oneRow = mysql_fetch_array($resultResource, MYSQL_ASSOC)) {
echo "<TR><TD>" . $oneRow["ID"] . "</TD></TR>";
}
// Closing connection
mysql_close($dbServerLink);
// Drop back out of php and complete the HTML table
?>
</table>