hi
i'd like to ouput my query results as a table that has 3 cols in each row.
It's for a photo gallery which has 3 columns of thumbnails that link to the big photos
I have no problems setting up a 'while()' loop to do the rows, but how do i do the 3 columns across each row ?
At a guess i'd say i'd have to do a sort of sub-loop within each table row - but how do i split the results up into bunches of three and assign them to each of the three cells in each row ??
If there's a "standard" way of doing this, could someone tell me ?
.... or a workaround .... or just an idea
thanks
3 columns in each row in my table ....
Moderator: General Moderators
-
VisionsOfCody
- Forum Commoner
- Posts: 30
- Joined: Sat Mar 01, 2003 1:19 pm
- Location: France
- Wayne Herbert
- Forum Commoner
- Posts: 34
- Joined: Tue Apr 29, 2003 3:13 pm
- Location: Houston, Texas
I've written a php script which does pretty much as you want. It runs this site:
http://www.herbhost.com/seasia/index.htm
Not only does it lay out the thumbnails 4 up, it limits the total thumbs per page to 28 (for non high speed connection page loads), and it also prevents orphan pages with only a few photos, that is, if there are 36 or fewer photos on the last page or any page, then they all go on one page.
The script is a bit long to post here, but if you are interested, email me, and I will supply you with the three scripts that drive the site.
The following sample code will put every record that you have selected on the same page, 3 up, and will blank fill any table cells in the last row.
http://www.herbhost.com/seasia/index.htm
Not only does it lay out the thumbnails 4 up, it limits the total thumbs per page to 28 (for non high speed connection page loads), and it also prevents orphan pages with only a few photos, that is, if there are 36 or fewer photos on the last page or any page, then they all go on one page.
The script is a bit long to post here, but if you are interested, email me, and I will supply you with the three scripts that drive the site.
The following sample code will put every record that you have selected on the same page, 3 up, and will blank fill any table cells in the last row.
Code: Select all
<?php
// want to generate the last cells in the table if not a multiple of 3
$notdone = true;
echo "<table>";
while $notdone
{
echo "<tr>"; // define the row
for ($j = 1; $j <= 3; $j++)
{
// last row of pix may have less than 3 thumbs so fill
// so create cell only
if ($row = @ mysql_fetch_array($result))
{
echo "<td valign=top WIDTH="33%">"; // create the cell
// and build the stuff you want
} // if got a row
else // no more rows - make a blank cell entry
{
$notdone = false; // end the process
echo "<td valign=top WIDTH="33%">";
echo "<br> ";
}
echo "</td>"; // end the cell definition
} // end for j
echo "</tr>"; // end the row
} // while not done-
VisionsOfCody
- Forum Commoner
- Posts: 30
- Joined: Sat Mar 01, 2003 1:19 pm
- Location: France
-
VisionsOfCody
- Forum Commoner
- Posts: 30
- Joined: Sat Mar 01, 2003 1:19 pm
- Location: France
- Wayne Herbert
- Forum Commoner
- Posts: 34
- Joined: Tue Apr 29, 2003 3:13 pm
- Location: Houston, Texas
- Wayne Herbert
- Forum Commoner
- Posts: 34
- Joined: Tue Apr 29, 2003 3:13 pm
- Location: Houston, Texas