Will Will - 5 months ago 45
PHP Question

PHP Echo Table formatting. 3rd column to appear under row 1. Is it possible with Echo?

I am using PHP to pull back data from within MySQL. My basic web page and query is working ok for the most part. I am using echo to dump the results out to a table on screen. The code is as follows:

foreach ($dbh->query($sql) as $row){
echo "<tr>";
echo "<td'>".$row['DATAA']."</td>";
echo "<td'>".$row['DATAB']."</td>";
echo "<td'>".$row['DATAC']."</td>";
echo "</tr>";

I would like to do some slightly advanced formatting of the tables as follows:

Does anyone know if this is possible with the PHP Echo command?

I am having problems finding suggestions around the internet, due to PHP and HTML tables vs MySQL tables and rows and columns all getting mixed up on search results.

So any help or code samples would be appreciated.

Answer Source

Nothing to do with echo. you need to format your html (Use colspan) as below

foreach ($dbh->query($sql) as $row){ 
          echo '<tr>';
          echo '<td>'.$row['DATAA'].'</td>';
          echo '<td>'.$row['DATAB'].'</td>';
          echo '</tr>';
          echo '<tr>';
              echo '<td colspan="2">'.$row['DATAC'].'</td>';
          echo '</tr>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download