<?php
// here is the code that connects to the database. Note that the username
// and password are "hard-coded".
$username="php"; /* Your MySQL username/password goes here! */
$password="php";
$database="dbintro";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// list all users in the database in a table
// here we define the SQL command
$query = "SELECT * FROM people";
// submit the query to the database
$res=mysql_query($query);
// make sure it worked!
if (!$res) {
mysql_error();
exit;
}
// find out how many records we got
$num = mysql_numrows($res);
echo "<table><tr><th>Name</th><th>Username</th></tr>\n";
// show all the records
for ($i=0;$i<$num;$i++) {
$fname = mysql_result($res,$i,'FirstName');
$lname = mysql_result($res,$i,'LastName');
$username = mysql_result($res,$i,'Username');
echo "<tr><td>$fname $lname</td><td>$username</td></tr>\n";
}
echo "</table>\n";
?> |