|
Posted by Marcin Dobrucki on 09/27/05 11:34
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
Navigation:
[Reply to this message]
|