PDA

View Full Version : MYSQL Grid Display


zimmer3
6-21-04, 11:27 PM
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 !

B&T
6-22-04, 01:13 AM
So what's the question? Read the database and populate a table :confused:

zimmer3
6-22-04, 02:00 AM
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>&nbsp;</td>"
$index++;
}
echo "</tr></table>";