Jump to content

easy php and table question


swissbeets

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/117582-easy-php-and-table-question/
Share on other sites

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.