[prog] php and formatting html tables

Marco Linux breakthru at inwind.it
Mon Aug 8 08:57:41 EST 2005


Alle 00:33, lunedì 8 agosto 2005, Wolf Rising ha scritto:
> 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>';
>
> 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):

you could use an auxiliary variable..
// inizialize to the first entry.
$CurrentB = 1; //this may be a problem,getting the first entry.
 echo '<table>';
     while($row = mysql_fetch_assoc($result)){
// if the BigNo value has changed, close table and open the next one
if ($row['BigNo']!=$CurrentB) echo '</tabe>\n<table><tr>Header</tr>\n';
    //display info to page
     echo '<tr>';
     echo '<td>' . $row['BlgNo'] . '<td>'; 
     echo '<td>' . $row['name'] . '</td>';
     echo '<td>' . $row['date']  . '</td>';
     echo '</tr>';
// update the curent BigNo.
$CurrentB = $row['BigNo'];
}//end while loop  
     echo '</table>';

This is the first time i post here. I hope that helps.
My name is Marco, i am from Naples, Italy.



More information about the Programming mailing list