0

i just want to display images ( that are stored into database )in a dynamically create table which has dynamically row & 4 columns in php
like this:-
image1|image2|image3|image4
image5|image6|image7|image8
image9|image10 etc.

if a new image i upload in the database than it should come in third row third column and so on.

pls reply me soon on my email id

2
Contributors
1
Reply
5
Views
7 Years
Discussion Span
Last Post by Froger93
0

You need to create a loop. If you are pulling the images from a database which I presume you are else the basis is pretty much the same.

<?php

// You need to connect to the database.
$pull_images = mysql_query("SELECT * FROM `images` ORDER BY `upload_time` ASC");

if( @mysql_num_rows( $pull_images ) > 0 ) {
echo '<table>';
$count = 0;
while( $row = mysql_fetch_array( $pull_images ) ) {
if( $count == 0 ) {
echo "<tr><td>";
} else {
echo "<td>";
}
echo '<img src="' . $row['src'] . '" alt="' . $row['title'] . '" />';
if( $count == 3 ) {
echo '</td></tr>';
$count = 0;
} else {
echo '<td>';
$count++;
}
}

$cells_left = 4 - $count;
if( $cells_left > 0 ) {
$i = 0;
while( $i <= $cells_left ) {
echo '<td></td>';
$i++;
}
echo '</tr>';
}
echo '</table>';
} else {
echo "No images in the database.";
}

?>
This topic has been dead for over six months. 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.