html php没有正确对齐每个列[关闭]

I m trying to run two loops the first query in retrieves the column .The second query takes the primary id of the first table and executes the query. Final result should be like given in the image

enter image description here Im not able to give the proper alignment

Below is the code

<table  width="100%" border="1" cellspacing="1" cellpadding="1"   >
<tr>
    <td>Col1</td>
    <td>col2</td>
    <td>col3</td>
    <td>col4/td>
  </tr>
<?php 

$mast = mysql_query("select * from table1 where av_master_id='".$_REQUEST['id']."'");
      while($res_mas= mysql_fetch_assoc($mast))
      {
      ?>
      <tr>
    <td><?php echo $res_mas['col1'];?></td>
    <?php 
     $room=  mysql_query("SELECT * FROM `table2` WHERE  av_room_id='".$res_mas['av_room_id']."'");

     while($res_room= mysql_fetch_assoc($room))
      {
      ?>

    <td><?php echo $res_room['col2'];?></td>
    <td><?php echo $res_room['col3'];?></td>
     <td><?php echo $res_room['col4'];?></td>


    </td>



    </tr><tr>

  <?php }?>
   </tr>

  <?php } ?>



  </table>

This should do it:

<table width="100%" border="1" cellspacing="1" cellpadding="1"   >
    <tr>
        <td>Col1</td>
        <td>col2</td>
        <td>col3</td>
        <td>col4/td>
    </tr>
<?php 

$mast = mysql_query("select * from table1 where av_master_id='".$_REQUEST['id']."'");
while($res_mas = mysql_fetch_assoc($mast)) {
    $room = mysql_query("SELECT * FROM `table2` WHERE  av_room_id='".$res_mas['av_room_id']."'");

    $count = 0;
    while($res_room= mysql_fetch_assoc($room)) {
        $count += 1;
?>
    <tr>
        <td><?php echo $count === 1 ? $res_mas['col1'] : "";?></td>
        <td><?php echo $res_room['col2'];?></td>
        <td><?php echo $res_room['col3'];?></td>
        <td><?php echo $res_room['col4'];?></td>
    </tr>
<?php } } ?>
</table>

(untested)