Forum Moderators: coopster

Message Too Old, No Replies

Divide any number by 3 and output results in 3 columns

How to do that ?

         

tomda

7:26 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As an example, I have 11 pictures to show in 3 columns.

I currently used:
$halfa=floor($numrows/3);
$halfb=floor($numrows/3);
$halfc=ceil($numrows/3);

so that it shows (and it works for any number)
3 pictures ¦¦ 3 pictures ¦¦ 5 pictures...

I would have prefer:
3 pictures ¦¦ 4 pictures ¦¦ 4 pictures...

Any suggestion?

adb64

7:49 am on Jan 20, 2006 (gmt 0)

10+ Year Member



tomda,

Order them from right-to-left to get the desired effect:

03 ¦¦ 02 ¦¦ 01
06 ¦¦ 05 ¦¦ 04
09 ¦¦ 08 ¦¦ 07
.. ¦¦ 11 ¦¦ 10

This will give you two columns with 4 images and 1 column with 3 images.

To calculate # images for each column in your situation:

$Column1 = floor($NrImages / 3);
$Column2 = floor(($NrImages + 1) / 3);
$Column3 = floor(($NrImages + 2) / 3);

For $NrImages = 11 you get:
$Column1 = 3
$Column2 = 4
$Column3 = 4