displaying query results as table
| From: | Sam Folk-Williams | Date: | Sun, 06 Apr 2003 18:08:13 +0000 |
| Subject: | displaying query results as table | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-26868@lists.php.net to get a copy of this message | ||
Hi,
I am querying a db table to return an array of months and teams that have
completed tasks in those months. Bascially it looks like [$month =>
$office_name] eg. [january => south office, january => north office,
february => south office]. I need to display this query in a table that
shows which offices have completed tasks for each month, like
January February
South Office South Office
North Office
This might be a basic question, but I can't figure out how to group the
results so you only see the month one time, and then the list of all offices
with that month. Instead, I get
January
South Office
January
North Office
February
South Office
Can anyone help? Thank you. -Sam
Here's the code:
$result = @mysql_query($sql,$connection) or die
("Problem executing database query." . mysql_error());
echo "<table width='500' border='0' cellspacing='0'
cellpadding='2'
class='mainText'>";
echo "<tr><td>";
echo"<table border='1' cellpadding='2' cellspacing='0'
bordercolor='#FF9900'>\n";
while ($row = mysql_fetch_array($result)) {
$office_name = $row['office_name'];
$month = $row['month'];
echo "<tr><td> $month<br>$office_name</td></tr>";
} //close while loop
echo "</table>\n";