[PHP] Re: Sorting data into columns vertically

2004-01-11 Thread dareal hamsta
Well you didn't say you wanted a dynamic number of columns...

Well I did* but thanks to yourself and Ralph I have what I'm looking for 
now, thanks very much. Much appreciated.

adam

* Obviously if the number of items and columns are static, I have no 
problem, but how do I get a layout that appeals to people and not computers 
if they're dynamic?

_
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Sorting data into columns vertically

2004-01-07 Thread Matt Grimm
Try this:

// Populate an array of random length
for ($i = 0; $i  rand(300, 600); $i++) {
$l_aTest[] = '...';
}
$l_iLength = count($l_aTest);
$l_iLow = floor($l_iLength / 3);
$l_iHigh = ceil($l_iLength / 3);
$l_iMod = $l_iLength % 3;

$l_iFirst  = $l_iHigh;
$l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
$l_iThird  = $l_iLow;

echo pstrongYour columns are: $l_iFirst, $l_iSecond,
$l_iThird/strong/p;

--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: [EMAIL PROTECTED]
Web: www.healthtvchannel.org


Dareal Hamsta [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 [ Please copy me off list. ]

 Say I have 7 items of data and I wish to sort them into 3 columns in a
HTML
 table. The items are unevenly sized, so rather than print them out in
rows -
 resulting in lots of wasteful whitespace - I would like to output them in
 vertical order. However if I use the modulus operator to check for when to
 break into a new column...

 foreach ($items as $item) {
 $counter++;
 if ( ($counter % $columns) == 0) {
 print /tdtd;
 }
 }

 ...the output will be something like this...

   +---+---+---+
   | Item1 | Item4 | Item7 |
   | Item2 | Item5 |   |
   | Item3 | Item6 |   |
   +---+

 ...when what I'm really looking for is this...

   +---+---+---+
   | Item1 | Item4 | Item6 |
   | Item2 | Item5 | Item7 |
   | Item3 |   |   |
   +---+

 Obviously if the number of items and columns are static, I have no
problem,
 but how do I get a layout that appeals to people and not computers if
 they're dynamic? This has me befuddled, I'm wondering is there an
algorithm
 for doing it or is it effectively a Turing Test.

 Thanks,
 adam


 ?php
 $s=array(74,65,112,104,112,72,32,59,45,41);
 for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
 ?

 _
 MSN 8 with e-mail virus protection service: 2 months FREE*
 http://join.msn.com/?page=features/virus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Sorting data into columns vertically

2004-01-07 Thread Matt Grimm
 $l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);

This should actually be:

$l_iSecond = ($l_iMod == 1 ? $l_iHigh - $l_iMod : $l_iHigh);

but it works both ways.

--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: [EMAIL PROTECTED]
Web: www.healthtvchannel.org

Matt Grimm [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Try this:

 // Populate an array of random length
 for ($i = 0; $i  rand(300, 600); $i++) {
 $l_aTest[] = '...';
 }
 $l_iLength = count($l_aTest);
 $l_iLow = floor($l_iLength / 3);
 $l_iHigh = ceil($l_iLength / 3);
 $l_iMod = $l_iLength % 3;

 $l_iFirst  = $l_iHigh;
 $l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
 $l_iThird  = $l_iLow;

 echo pstrongYour columns are: $l_iFirst, $l_iSecond,
 $l_iThird/strong/p;

 --
 Matt Grimm
 Web Developer
 The Health TV Channel, Inc.
 (a non - profit organization)
 3820 Lake Otis Parkway
 Anchorage, AK 99508
 907.770.6200 ext. 686
 907.336.6205 (fax)
 E-mail: [EMAIL PROTECTED]
 Web: www.healthtvchannel.org


 Dareal Hamsta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  [ Please copy me off list. ]
 
  Say I have 7 items of data and I wish to sort them into 3 columns in a
 HTML
  table. The items are unevenly sized, so rather than print them out in
 rows -
  resulting in lots of wasteful whitespace - I would like to output them
in
  vertical order. However if I use the modulus operator to check for when
to
  break into a new column...
 
  foreach ($items as $item) {
  $counter++;
  if ( ($counter % $columns) == 0) {
  print /tdtd;
  }
  }
 
  ...the output will be something like this...
 
+---+---+---+
| Item1 | Item4 | Item7 |
| Item2 | Item5 |   |
| Item3 | Item6 |   |
+---+
 
  ...when what I'm really looking for is this...
 
+---+---+---+
| Item1 | Item4 | Item6 |
| Item2 | Item5 | Item7 |
| Item3 |   |   |
+---+
 
  Obviously if the number of items and columns are static, I have no
 problem,
  but how do I get a layout that appeals to people and not computers if
  they're dynamic? This has me befuddled, I'm wondering is there an
 algorithm
  for doing it or is it effectively a Turing Test.
 
  Thanks,
  adam
 
 
  ?php
  $s=array(74,65,112,104,112,72,32,59,45,41);
  for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
  ?
 
  _
  MSN 8 with e-mail virus protection service: 2 months FREE*
  http://join.msn.com/?page=features/virus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Sorting data into columns vertically

2004-01-07 Thread dareal hamsta
I get:

Your columns are: 102, 101, 101

???

The other problem with this solution is that it's for a static number of 
columns, however I'm looking for a solution with dynamic variables. For 
example, I might want 4 columns with 100 items, or six columns with 15.

Thanks for trying though.

adam


From: Matt Grimm [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: Sorting data into columns vertically
Date: Wed, 07 Jan 2004 11:39:48 -0900
Try this:

// Populate an array of random length
for ($i = 0; $i  rand(300, 600); $i++) {
$l_aTest[] = '...';
}
$l_iLength = count($l_aTest);
$l_iLow = floor($l_iLength / 3);
$l_iHigh = ceil($l_iLength / 3);
$l_iMod = $l_iLength % 3;
$l_iFirst  = $l_iHigh;
$l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
$l_iThird  = $l_iLow;
echo pstrongYour columns are: $l_iFirst, $l_iSecond,
$l_iThird/strong/p;
--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: [EMAIL PROTECTED]
Web: www.healthtvchannel.org
Dareal Hamsta [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 [ Please copy me off list. ]

 Say I have 7 items of data and I wish to sort them into 3 columns in a
HTML
 table. The items are unevenly sized, so rather than print them out in
rows -
 resulting in lots of wasteful whitespace - I would like to output them 
in
 vertical order. However if I use the modulus operator to check for when 
to
 break into a new column...

 foreach ($items as $item) {
 $counter++;
 if ( ($counter % $columns) == 0) {
 print /tdtd;
 }
 }

 ...the output will be something like this...

   +---+---+---+
   | Item1 | Item4 | Item7 |
   | Item2 | Item5 |   |
   | Item3 | Item6 |   |
   +---+

 ...when what I'm really looking for is this...

   +---+---+---+
   | Item1 | Item4 | Item6 |
   | Item2 | Item5 | Item7 |
   | Item3 |   |   |
   +---+

 Obviously if the number of items and columns are static, I have no
problem,
 but how do I get a layout that appeals to people and not computers if
 they're dynamic? This has me befuddled, I'm wondering is there an
algorithm
 for doing it or is it effectively a Turing Test.

 Thanks,
 adam


 ?php
 $s=array(74,65,112,104,112,72,32,59,45,41);
 for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
 ?

 _
 MSN 8 with e-mail virus protection service: 2 months FREE*
 http://join.msn.com/?page=features/virus



_
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Sorting data into columns vertically

2004-01-07 Thread Matt Grimm
Well you didn't say you wanted a dynamic number of columns...

What's the problem with the solution 102, 101, 101?  That's the count of the
elements in each column -- you said in a 7 member array, you wanted 3 items
in the first column, and two in the other two columns.  That's 3, 2, 2,
which the code will give you.  If you want, echo the other variables and it
will make more sense.

--
Matt Grimm


Dareal Hamsta [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I get:

 Your columns are: 102, 101, 101

 ???

 The other problem with this solution is that it's for a static number of
 columns, however I'm looking for a solution with dynamic variables. For
 example, I might want 4 columns with 100 items, or six columns with 15.

 Thanks for trying though.

 adam


 From: Matt Grimm [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: Sorting data into columns vertically
 Date: Wed, 07 Jan 2004 11:39:48 -0900
 
 Try this:
 
 // Populate an array of random length
 for ($i = 0; $i  rand(300, 600); $i++) {
  $l_aTest[] = '...';
 }
 $l_iLength = count($l_aTest);
 $l_iLow = floor($l_iLength / 3);
 $l_iHigh = ceil($l_iLength / 3);
 $l_iMod = $l_iLength % 3;
 
 $l_iFirst  = $l_iHigh;
 $l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
 $l_iThird  = $l_iLow;
 
 echo pstrongYour columns are: $l_iFirst, $l_iSecond,
 $l_iThird/strong/p;
 
 --
 Matt Grimm
 Web Developer
 The Health TV Channel, Inc.
 (a non - profit organization)
 3820 Lake Otis Parkway
 Anchorage, AK 99508
 907.770.6200 ext. 686
 907.336.6205 (fax)
 E-mail: [EMAIL PROTECTED]
 Web: www.healthtvchannel.org
 
 
 Dareal Hamsta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
   [ Please copy me off list. ]
  
   Say I have 7 items of data and I wish to sort them into 3 columns in a
 HTML
   table. The items are unevenly sized, so rather than print them out in
 rows -
   resulting in lots of wasteful whitespace - I would like to output them
 in
   vertical order. However if I use the modulus operator to check for
when
 to
   break into a new column...
  
   foreach ($items as $item) {
   $counter++;
   if ( ($counter % $columns) == 0) {
   print /tdtd;
   }
   }
  
   ...the output will be something like this...
  
 +---+---+---+
 | Item1 | Item4 | Item7 |
 | Item2 | Item5 |   |
 | Item3 | Item6 |   |
 +---+
  
   ...when what I'm really looking for is this...
  
 +---+---+---+
 | Item1 | Item4 | Item6 |
 | Item2 | Item5 | Item7 |
 | Item3 |   |   |
 +---+
  
   Obviously if the number of items and columns are static, I have no
 problem,
   but how do I get a layout that appeals to people and not computers if
   they're dynamic? This has me befuddled, I'm wondering is there an
 algorithm
   for doing it or is it effectively a Turing Test.
  
   Thanks,
   adam
  
  
   ?php
   $s=array(74,65,112,104,112,72,32,59,45,41);
   for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
   ?
  
   _
   MSN 8 with e-mail virus protection service: 2 months FREE*
   http://join.msn.com/?page=features/virus
 
 
 

 _
 Add photos to your messages with MSN 8. Get 2 months FREE*.
 http://join.msn.com/?page=features/featuredemail

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Sorting data into columns vertically

2004-01-07 Thread Matt Grimm
Ok, I think this is more what you're looking for.  Dynamic columns *and*
rows.  This work for ya?

// How many columns do you want?
$l_iColumnWidth = 6;

// Populate an array of random length with random values
for ($i = 0; $i  rand(15, 300); $i++) {
$l_aTest[] = '...';
}

$l_iLength = count($l_aTest);
$l_iLow = floor($l_iLength / $l_iColumnWidth);
$l_iHigh = ceil($l_iLength / $l_iColumnWidth);
$l_iMod = $l_iLength % $l_iColumnWidth;

if ($l_iColumnWidth  $l_iLength) {
die('Too many columns for this array length!');
} else {
echo 'Array length: '.count($l_aTest);
}

// Do high columns first
for ($i = 0; $i  $l_iMod; $i++) {
$l_aTable[column$i] = $l_iHigh;
}
// Do the rest
for ($i = count($l_aTable); $i  $l_iColumnWidth; $i++) {
$l_aTable[column$i] = $l_iLow;
}

echo 'preResult:br /'; print_r($l_aTable);

--
Matt Grimm


Dareal Hamsta [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I get:

 Your columns are: 102, 101, 101

 ???

 The other problem with this solution is that it's for a static number of
 columns, however I'm looking for a solution with dynamic variables. For
 example, I might want 4 columns with 100 items, or six columns with 15.

 Thanks for trying though.

 adam


 From: Matt Grimm [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: Sorting data into columns vertically
 Date: Wed, 07 Jan 2004 11:39:48 -0900
 
 Try this:
 
 // Populate an array of random length
 for ($i = 0; $i  rand(300, 600); $i++) {
  $l_aTest[] = '...';
 }
 $l_iLength = count($l_aTest);
 $l_iLow = floor($l_iLength / 3);
 $l_iHigh = ceil($l_iLength / 3);
 $l_iMod = $l_iLength % 3;
 
 $l_iFirst  = $l_iHigh;
 $l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
 $l_iThird  = $l_iLow;
 
 echo pstrongYour columns are: $l_iFirst, $l_iSecond,
 $l_iThird/strong/p;
 
 --
 Matt Grimm
 Web Developer
 The Health TV Channel, Inc.
 (a non - profit organization)
 3820 Lake Otis Parkway
 Anchorage, AK 99508
 907.770.6200 ext. 686
 907.336.6205 (fax)
 E-mail: [EMAIL PROTECTED]
 Web: www.healthtvchannel.org
 
 
 Dareal Hamsta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
   [ Please copy me off list. ]
  
   Say I have 7 items of data and I wish to sort them into 3 columns in a
 HTML
   table. The items are unevenly sized, so rather than print them out in
 rows -
   resulting in lots of wasteful whitespace - I would like to output them
 in
   vertical order. However if I use the modulus operator to check for
when
 to
   break into a new column...
  
   foreach ($items as $item) {
   $counter++;
   if ( ($counter % $columns) == 0) {
   print /tdtd;
   }
   }
  
   ...the output will be something like this...
  
 +---+---+---+
 | Item1 | Item4 | Item7 |
 | Item2 | Item5 |   |
 | Item3 | Item6 |   |
 +---+
  
   ...when what I'm really looking for is this...
  
 +---+---+---+
 | Item1 | Item4 | Item6 |
 | Item2 | Item5 | Item7 |
 | Item3 |   |   |
 +---+
  
   Obviously if the number of items and columns are static, I have no
 problem,
   but how do I get a layout that appeals to people and not computers if
   they're dynamic? This has me befuddled, I'm wondering is there an
 algorithm
   for doing it or is it effectively a Turing Test.
  
   Thanks,
   adam
  
  
   ?php
   $s=array(74,65,112,104,112,72,32,59,45,41);
   for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
   ?
  
   _
   MSN 8 with e-mail virus protection service: 2 months FREE*
   http://join.msn.com/?page=features/virus
 
 
 

 _
 Add photos to your messages with MSN 8. Get 2 months FREE*.
 http://join.msn.com/?page=features/featuredemail

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Sorting data into columns vertically

2004-01-07 Thread Martin Towell
given: $num_cols and $num_items

$num_with_extra = $num_items % $num_cols;
$num_per_col = floor($num_items / $num_cols);

the first $num_with_extra columns has $num_per_col+1 items in it
and the rest have $num_per_col items in it

(not tested in code, but looks okay in theory...)

Martin

 -Original Message-
 From: Matt Grimm [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 8 January 2004 9:37 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: Sorting data into columns vertically
 
 
 Well you didn't say you wanted a dynamic number of columns...
 
 What's the problem with the solution 102, 101, 101?  That's 
 the count of the
 elements in each column -- you said in a 7 member array, you 
 wanted 3 items
 in the first column, and two in the other two columns.  
 That's 3, 2, 2,
 which the code will give you.  If you want, echo the other 
 variables and it
 will make more sense.
 
 --
 Matt Grimm
 
 
 Dareal Hamsta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  I get:
 
  Your columns are: 102, 101, 101
 
  ???
 
  The other problem with this solution is that it's for a 
 static number of
  columns, however I'm looking for a solution with dynamic 
 variables. For
  example, I might want 4 columns with 100 items, or six 
 columns with 15.
 
  Thanks for trying though.
 
  adam
 
 
  From: Matt Grimm [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Subject: Re: Sorting data into columns vertically
  Date: Wed, 07 Jan 2004 11:39:48 -0900
  
  Try this:
  
  // Populate an array of random length
  for ($i = 0; $i  rand(300, 600); $i++) {
   $l_aTest[] = '...';
  }
  $l_iLength = count($l_aTest);
  $l_iLow = floor($l_iLength / 3);
  $l_iHigh = ceil($l_iLength / 3);
  $l_iMod = $l_iLength % 3;
  
  $l_iFirst  = $l_iHigh;
  $l_iSecond = ($l_iMod  2 ? $l_iHigh - $l_iMod : $l_iHigh);
  $l_iThird  = $l_iLow;
  
  echo pstrongYour columns are: $l_iFirst, $l_iSecond,
  $l_iThird/strong/p;
  
  --
  Matt Grimm
  Web Developer
  The Health TV Channel, Inc.
  (a non - profit organization)
  3820 Lake Otis Parkway
  Anchorage, AK 99508
  907.770.6200 ext. 686
  907.336.6205 (fax)
  E-mail: [EMAIL PROTECTED]
  Web: www.healthtvchannel.org
  
  
  Dareal Hamsta [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
[ Please copy me off list. ]
   
Say I have 7 items of data and I wish to sort them into 
 3 columns in a
  HTML
table. The items are unevenly sized, so rather than 
 print them out in
  rows -
resulting in lots of wasteful whitespace - I would like 
 to output them
  in
vertical order. However if I use the modulus operator 
 to check for
 when
  to
break into a new column...
   
foreach ($items as $item) {
$counter++;
if ( ($counter % $columns) == 0) {
print /tdtd;
}
}
   
...the output will be something like this...
   
  +---+---+---+
  | Item1 | Item4 | Item7 |
  | Item2 | Item5 |   |
  | Item3 | Item6 |   |
  +---+
   
...when what I'm really looking for is this...
   
  +---+---+---+
  | Item1 | Item4 | Item6 |
  | Item2 | Item5 | Item7 |
  | Item3 |   |   |
  +---+
   
Obviously if the number of items and columns are 
 static, I have no
  problem,
but how do I get a layout that appeals to people and 
 not computers if
they're dynamic? This has me befuddled, I'm wondering 
 is there an
  algorithm
for doing it or is it effectively a Turing Test.
   
Thanks,
adam
   
   
?php
$s=array(74,65,112,104,112,72,32,59,45,41);
for($i=0;$icount($s);$i++){echo'#'.$s[$i].';';}
?
   

 _
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus
  
  
  
 
  _
  Add photos to your messages with MSN 8. Get 2 months FREE*.
  http://join.msn.com/?page=features/featuredemail
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 __ Information from NOD32 1.594 (20040107) __
 
 This message was checked by NOD32 for Exchange e-mail monitor.
 http://www.nod32.com
 
 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php