Re: putting database results in a 5x1 table
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: putting database results in a 5x1 table

From: Marcin Dobrucki <Marcin.Dobrucki@TAKETHISAWAY.nokia.com>
Date: Tue Sep 27 2005 - 10:34:11 CEST

Eddie Biscomb wrote:
> I have a db of tens of thousands of entries. It's not too hard to pull
...
> I want to pull about 200 records at a time from the db and display as
> described above. How can I tell php to take five records from my result
> set and display above, then loop through the result set until I'm done?

This will stretch the last column to fill the missing space.

<?php
require_once ("HTML/Table.php");
$sample_data = array ("john", "fred", "bob", "willy", "angie",
        "frank", "betty", "george", "wilma", "dexter",
        "jack", "ziggy", "flo", "shrek", "gork", "nobody");

function build(&$input, $cols = 5) {
   $t = new HTML_Table(array("border" => 1));
   $t->setAutoGrow(true);

   $array_size = count($input);
   $line = 0;

   for ($offset = 0; $offset < $array_size; $offset = $offset + $cols) {
     $row = array_splice($input, 0, $cols);
     $row_size = count($row);
     $t->addRow($row);
     if ($row_size < 5) {
       $t->setCellAttributes($line, $row_size - 1,
                             array("colspan" => 5 - $row_size +1));
     }
     $line++;
   }
   return $t;
}

$res =& build($sample_data);
$res->display();
?>

You can also remove the lines that handle the "stretch", and just add
the result of the splice. The non-existant cells will be handled by
setAutoGrow then.

/m
Received on Tue Oct 18 02:28:35 2005