Print

Print


=> On Mon, 23 Dec 2002 08:45:01 -0500, Joseph A carusone Jr <[log in to unmask]> said:


> Well, we can have the wine you buy while we are discussing the wording
> of the mission statement...

An official whine committe?  Dang, I want to be on that.


I just had to do the "I've got a long list, I want it in columns" thing.
Here's some example code.  It's derived from PERL, but I've added comments
that will make it read more clearly yet not compile. :)

This code is predicated on the idea that you've got a list of things, and that
you have essentially random-access to that list.  A cursor would work, an
array is simplest (but eats memory for large ones).

What you do is essentially iterate through the positions in your columnwise
table, _in the order you'd like the output to appear in your HTML_.

for each page
    for each row
        for each column
            calculate which cell I want here
            output it.

In order for this algorithm to work, you have to set the page length _short_
enough that you force data to a second column.  For an infinite page length,
everything goes in column 1.

Additionally: Everyone remember your order of operations.  I cussed at myself
for some time when I remembered that N - 1 * m equals N - (1*m), instead of
(N-1) *m.  Grump.


my $count = ( count the number of items )
my $cols = 2;             #
my $rows = 55;            # In a page.
my $npp = $rows * $cols;  # NPP = Number Per Page.

my $np = $count / $npp;   # Ergo, how many pages.
$np = int($np + .999);    # Round up.

for ($p = 1; $p <= $np ; $p++)
{
    for ( $r = 1; $r <= $rows ; $r++)
    {
        for ( $c = 1 ; $c <= $cols ; $c++ )
        {
            $n = ( ($p-1) * $npp ) + ( ($r-1) * $cols )  + ( $c-1 ) ;
            Output item $n from your structure.
        }
        Close a line (newline?  <BR> </tr>?)
    }
    Close a page (^L? </table> ?)
}


- Allen S. Rout