Week 10: Database Modeling and Querying
Partner Database Example
In class, we looked at a PHP report example (based on the partner data):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
<head>
<title>Partner Report</title>
</head>
<body>
<center><img src="http://theoceanproject.org/wp-content/themes/ocean/img/header.png" /></center>
<div style="position:absolute;top:240px;left:50%;margin-left:-200px;">
<h1>Number of Partners by Location</h1>
<?php
//Connect To Database
$hostname='localhost';
$username='bdc';
$password='password';
$dbname='partner';
$query = 'SELECT state, COUNT(state) AS count FROM partner GROUP BY state ORDER by count DESC, state ASC';
//echo $query;
mysql_connect($hostname, $username, $password) OR DIE (mysql_error());
mysql_select_db($dbname);
$result = mysql_query($query);
if($result) {
echo '<table>';
while($row = mysql_fetch_array($result)) {
echo '<tr><td>'.$row['state'].'</td><td>'.$row['count'].'</td></tr>';
echo "\n";
}
echo '</table>';
}
?>
</div>
</body>
</html>
|