0

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>
4
Contributors
5
Replies
8
Views
6 Years
Discussion Span
Last Post by andy106
1

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>
Votes + Comments
useful post
0

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>>

Edited by Nick Evan: Removed self-promotion

0

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

-Damon Tavangar

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.