Is it possible to display left to right

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
qup41
Forum Newbie
Posts: 2
Joined: Wed Jul 16, 2003 6:38 pm
Location: Gold Coast

Is it possible to display left to right

Post 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 :roll:
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

I may presume too much but...

Post 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++)
&#123;
$output .= ($i%3==0?"<tr>":"");
$output .= "<td><img src="".$i.".jpg"></td>";
$output .= ((($i+1)%3==0)||($i==$noOfItems-1)?"</tr>":"");
&#125;
$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

Code: Select all

$output .= ($i%3==0?"<tr>":"");
This means IF $i divided by 3 leaves a remainder of 0 then $output = $output + "<tr>" ELSE $output = $output + ""
"" is of course null.
Lee
Post Reply