Page 1 of 1
3 columns in each row in my table ....
Posted: Tue May 20, 2003 1:23 pm
by VisionsOfCody
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
Posted: Tue May 20, 2003 1:40 pm
by Wayne Herbert
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.
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
Posted: Tue May 20, 2003 1:59 pm
by VisionsOfCody
that is
BRILLIANT - thanks
just one thing though - what does the "@" mean in this line ? :
if ($row = @ mysql_fetch_array($result))
i don't think i've seen that before
thanks again
Posted: Tue May 20, 2003 2:03 pm
by JPlush76
the @ sign suppresses errors so that if it doesn't get a value it doesn't put a dirty error message on the screen to the user
Posted: Tue May 20, 2003 2:06 pm
by VisionsOfCody
ooooh - i
Like that !!
thanks again both

Posted: Tue May 20, 2003 4:20 pm
by Wayne Herbert
VisionsOfCody wrote:that is
BRILLIANT - thanks
Eh?? Er... ahem... thanks!...

... but, I suspect that these lines of code have been written millions of times before I ever wrote them down. Now, six dimensional arrays are a bit more uncommon.
Posted: Tue May 20, 2003 4:22 pm
by JPlush76
mmmm multi demensional
(homer simpson voice)
Posted: Tue May 20, 2003 4:32 pm
by Wayne Herbert