View Full Version : MYSQL Grid Display
Hello,
I have a gallery thing I created, that stores the URLs of the pictures in a MySQL. I am trying to create an opening page that will display the thumbs (part of the db info) in a grid 4 wide by 3 high. I am trying to use tables, not CSS, to do this.
Any ideas appreciated.
Thanks !
So what's the question? Read the database and populate a table :confused:
I want to display 12 rows of data, where each row is represented by 1 cell in the table, which is 4 cells wide and 3 high.
1 2 3 4
5 6 7 8
9 10 11 12
how would I display the 12 rows in this manner, normally I use a while() display all records, but how would I adapt that to insert the </tr><tr> in the correct spots?
mitchind
6-22-04, 03:16 AM
If you're getting 12 records at a time use two loops - here's some pseudo code.
for iRow = 1 to 3
echo "<tr>"
for iCol = 1 to 4
echo "<td>" . $img
next iCol
next iRow
You should be able to figure it out from here.
jdinbrla
7-22-04, 08:49 PM
try this:
$imgRes = mysql_query('SELECT image_url FROM mygallery');
$index = 0;
echo "<table><tr>\n";
while($imgRow = mysql_fetch_row($imgRes)) {
if($index % 4 == 0)
echo "</tr><tr>";
$text = "<img src=\"{$imgRow[0]}\">";
echo "<td>$text</td>";
$index++;
}
while($index % 4 != 0) {
echo "<td> </td>"
$index++;
}
echo "</tr></table>";
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.