hi i display images from database, i want that there should be at most 4 photos in each row,when the number photos exceeds 4, it should displays the remaining images in next rows, the code i have written displays all images in the same row, i don't know how to deal with it. i used while loop for displaying images.

here is the code

<table width="86" border="0" align="center">
        <tr>
		<?php 
		while($show_std=mysql_fetch_assoc($get_stds)){?>
          <td class="std_success_td"><img class="stdpic_success" src="<?php echo "uploads/".$show_std['std_pic'];?>"/></td>
		 
		 
		 <?php  }?>
        </tr>
      </table>

Recommended Answers

All 5 Replies

This will solve part of it:

<table width="86" border="0" align="center">
<?php 
  $count = 0;
  while($show_std = mysql_fetch_assoc($get_stds)) {
    if ($count % 4 = 0)
      echo '<tr>';

    echo "<td class='std_success_td'><img class='stdpic_success' src='uploads/{$show_std['std_pic']}' /></td>";
 
    if ($count % 4 = 3)
      echo '</tr>';

    $count++;
  }
?>
</table>
commented: useful post +5

this worked thanks

this worked thanks

there is actually an error in that code, it should be:

<table width="86" border="0" align="center">
    <?php
    $count = 0;
    while($show_std = mysql_fetch_assoc($get_stds)) {
    if ($count % 4 = 0)
    echo '<tr>';
     
    echo "<td class='std_success_td'><img class='stdpic_success' src='uploads/{$show_std['std_pic']}' /></td>";
     
    if ($count % 4 == 3) // == instead of =
    echo '</tr>';
     
    $count++;
    }
    ?>
    </table>

Damon Tavangar
<<snip>>

Nice catch, although you missed the similar issue in line 6.

hahah ofcourse! thanks for the code though, it works like a charm :)

-Damon Tavangar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.