Page 1 of 1
Is it possible to display left to right
Posted: Wed Jul 16, 2003 6:38 pm
by qup41
Hi All
I am developing a site, which has a photo gallery and I know how to display results in a table top to bottom like a list, But Does anyone one to display a 3xN matrix??
Thank you
Armando

Posted: Mon Jul 21, 2003 8:02 am
by Johnm
I may presume too much but...
Posted: Mon Jul 21, 2003 8:31 am
by leenoble_uk
I think he means, how do you echo out a shed load of images into a table three columns wide bearing in mind you'll have to add tr and /tr every third image.
Code: Select all
$output = "<table>";
for (i = 0; i < $noOfItems; $i++)
{
$output .= ($i%3==0?"<tr>":"");
$output .= "<td><img src="".$i.".jpg"></td>";
$output .= ((($i+1)%3==0)||($i==$noOfItems-1)?"</tr>":"");
}
$output .= "</table>";
echo $output;
The % symbol if I recall correctly gives the remainder of one number divided by another so 7%3 is 2 remainder 1. So in this script it tests for multiples of 3.
I'm not at my normal computer so I can't check how I've done this previously. I'd also stick a few newline chars in there to clean up the resulting html.
Hope I got it right and that's what you meant. And then I hope I got the answer right.
In case you were not aware two of the lines use a shorthand if statement. So where it says
This means IF $i divided by 3 leaves a remainder of 0 then $output = $output + "<tr>" ELSE $output = $output + ""
"" is of course null.
Lee