Adding New <tr> when <td> increases!!

Discussion in 'PHP' started by ausgezeichnete, Jan 15, 2008.

  1. #1
    this is my code it echos images in <td>
    Now,if i want it to make new <tr> if the <td> is becoming more than 3
    ex:i have 6 images,using this code will show me them under eachother
    but i want every <tr>to have only 3 <td> and then if the number of images increase more than 3,it make new <tr> to the rest of the images
    what can i do????
    
    $sql=mysql_query("Select * from clients");
    <tr>
    	  <?php do { ?>
            <td>
              <a href="client_view.php?client_images_id=<?php echo $row_Recordset1['client_images_id']; ?>"><img src="Admin/<?php echo $row_Recordset1['client_images_fotos']; ?>" width="170" height="170">          </a>        </td>
    		      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
          </tr>
    
    
    PHP:

     
    ausgezeichnete, Jan 15, 2008 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The same question was asked yesterday here:

    http://forums.digitalpoint.com/showthread.php?t=652877
     
    SmallPotatoes, Jan 15, 2008 IP
  3. ausgezeichnete

    ausgezeichnete Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thnxxxx i found the answer ,check it
    
    <?php
    $cols = 3;
    $counter = 1;
    while($row_Recordset1 = mysql_fetch_assoc($Recordset1)){?>
    
    <td>
    <a href="client_view.php?client_images_id=<?php echo $row_Recordset1['client_images_id']; ?>"
    <img src="Admin/<?php echo $row_Recordset1['client_images_fotos']; ?>" width="170" height="170"></a>
    </td>
    
    <?php if($counter % $cols == 0)
            echo '</tr><tr>';
        $counter++;
    }?>
    </tr>
    </table>
    
    
    PHP:
     
    ausgezeichnete, Jan 15, 2008 IP