[prog] php and formatting html tables

Wolf Rising wolfrising at gmail.com
Mon Aug 8 08:33:13 EST 2005


Hi,

I have this bit of code which prints out one large table:

     echo '<table>';
     while($row = mysql_fetch_assoc($result)){
    //display info to page
     echo '<tr>';
     echo '<td>' . $row['BlgNo'] . '<td>'; 
     echo '<td>' . $row['name'] . '</td>';
     echo '<td>' . $row['date']  . '</td>';
     echo '</tr>';
}//end while loop  
     echo '</table>';

and this is the result

+--------+--------+---------------+
| BlgNo  | name   | date          |
+--------+--------+---------------+
|      1 | Bob    | 2005-07-23    |
|      1 | Ralph  | 2005-07-17    |
|      1 | Jean   | 2005-07-18    |
|      1 | Mich   | 2005-07-22    |
|      1 | Jacki  | 2005-07-15    |
|      1 | Anne   | 2005-07-19    |
|      2 | Tom    | 2005-07-15    |
|      2 | B.J.   | 2005-07-31    |
|      2 | Ann    | 2005-07-07    |
|      2 | Sandy  | 2005-07-06    |
|      2 | Kyle   | 2005-07-01    |
|      3 | Chris  | 2005-07-15    |
|      3 | Jerry  | 2005-07-18    |
|      3 | Steve  | 2005-07-15    |
|      3 | Susan  | 2005-07-25    |
+--------+--------+---------------+

what I would like to have is for it to break into separate tables per
building number (this is a small print out there are 10 buildings):

+--------+--------+---------------+
| BlgNo  | name   | date          |
+--------+--------+---------------+
|      1 | Bob    | 2005-07-23    |
|      1 | Ralph  | 2005-07-17    |
|      1 | Jean   | 2005-07-18    |
|      1 | Mich   | 2005-07-22    |
|      1 | Jacki  | 2005-07-15    |
|      1 | Anne   | 2005-07-19    |
+--------+--------+---------------+

+--------+--------+---------------+
| BlgNo  | name   | date          |
+--------+--------+---------------+
|      2 | Tom    | 2005-07-15    |
|      2 | B.J.   | 2005-07-31    |
|      2 | Ann    | 2005-07-07    |
|      2 | Sandy  | 2005-07-06    |
|      2 | Kyle   | 2005-07-01    |
+--------+--------+---------------+

+--------+--------+---------------+
| BlgNo  | name   | date          |
+--------+--------+---------------+
|      3 | Chris  | 2005-07-15    |
|      3 | Jerry  | 2005-07-18    |
|      3 | Steve  | 2005-07-15    |
|      3 | Susan  | 2005-07-25    |
+--------+--------+---------------+

is it possible to modify the loop so it would print separate tables? I
tried adding
an if statement if($row['Blg'] ==1) but that didn't work out very well
and it would
get kinda messy. 

Thanks!


More information about the Programming mailing list