Hey All,
I have a simple query form that displays from a mysql database, a list of names and phone numbers. What i'd like is a column heading at the top of the page but I can't seem to figure out how to put it in there. Here is my code so far:
<?php
// set database server access variables:
$host = "localhost";
$user = "user";
$pass = "password";
$db = "phonebook";
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query = "SELECT * FROM people ORDER BY fname ASC";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=0>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[4]."</td>";
echo "<td>".$row[5]."</td>";
echo "<td>".$row[6]."</td>";
echo "<td>".$row[7]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
I don't want to use the actual table names because they are abbreviated, ie fname = First Name. But I do want to let the viewer know what each of the columns are. How can I do this.
Thanks.