swissbeets Posted July 31, 2008 Share Posted July 31, 2008 im sure this is an easy question i just havent done it before, i need to list my pictures in a table that will continuously show them but only show about 4 per line. right now i have something like this <table border="1"> while($row = mysql_fetch_array($photos)) { ?> <tr> <td><?php $picture = "images/" . $row['image_source']; mysql_prep($picture); ?><img src="<?php print $picture;?> "width="120" height="120"> </td> <?php }?> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/117582-easy-php-and-table-question/ Share on other sites More sharing options...
discomatt Posted July 31, 2008 Share Posted July 31, 2008 Here's a basic example of what you wanna do. If you don't understand the logic i can help explain a little more <?php # How many total colums $columns = 4; # Start the table echo "<table border=\"1\">\n"; # Set our current working column at 0 $column = 0; # Begin to loop through results while ( $row = mysql_fetch_assoc($photos) ) { # Check if we need to start a new row if ( $column == $columns ) { # End current row echo " </tr>\n"; # Reset current working column back to 0 ( starting a new row ) $column = 0; } # Check to see if a new row needs to be started if ( $column == 0 ) # Start new row echo " <tr>\n"; # Output cell contents echo " <td><img src=\"{$row['picture']}\" alt=\"{$row['description']}\" /></td>\n"; # Increase current working column by 1 $column++; } # Check to see if we have left over cells while ( $column < $columns ) { # Output a blank cell echo " <td> </td>\n"; # Increase current working column by 1 $column++; } # End final row echo " </tr>\n"; #End the table echo "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/117582-easy-php-and-table-question/#findComment-604812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.