Let's access the database test_1 and the table wines on server cybil with Php
We will list all eight fields in the wines table located on cybil
<?
// Connect to mysql server and select the database server, username and password
// Select the database test_1 containing the table wines
// test_1 has empty fields for mysql username and password
mysql_connect('cybil.tafeitltn.com.au','capsticm','');
mysql_select_db('test_1');
// Run Query and store results in the row array
$result= mysql_query("select * from wines;");
$row=mysql_fetch_array($result);
// display the 8 columns of results in a table by
// looping through the array of results, $result,
print "<body bgcolor='ffeecc'>";
echo "<table>";
do {
echo "<tr>";
echo "<td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2];
echo "</td><td>".$row[3]."</td><td>".$row[4];
echo "</td><td>".$row[5]."</td><td>".$row[6]."</td><td>".$row[7]."</td>";
echo "</tr>";
} while ($row= mysql_fetch_array($result));
print "</table></body>";
?>
Exercise
1. Read the code carefully, remember comments are preceeded by //.
Enter the code and get the program working.
2. Rewrite the php script to display only the red wines and their costs
$result= mysql_query("select * from wines where category='Dry Red';");