954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

displaying images in more than one lines (rows)

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>
shahiduop
Newbie Poster
9 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

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>
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

this worked thanks

shahiduop
Newbie Poster
9 posts since Nov 2010
Reputation Points: 10
Solved Threads: 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<>

damonT
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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

-Damon Tavangar

andy106
Newbie Poster
20 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: