Hi David,
The script below generates a simple table, I would like to break the current table (about 100 items) in a multi-column display, eg 4 tables next to each other, floating left. In other words after counting 25 rows the table should be closed and a new one opened with the next 25 items. And so on. I guess I have to use something like if($count%25 == 0) but I am not sure how exactly to do that.
Perhaps you can help. Below is my script. Thanks for the help!
<?php
require("MagicParser.php");
global $records;
$records=array();
function myRecordHandler($record){
global $records;
$records[] = $record;
}
MagicParser_parse("filename.XML","myRecordHandler","xml|ALLITEMS/ITEM/");
print "<table width='225' class='mp-table'>";
foreach($records as $record)
{
print "<tr>
<td><img src='/xml/".$record["DESTINATION"].".jpg' alt='".$record["DESTINATION"]."' title='".$record["DESTINATION"]."' height='40' width='80' /></td>
<td>".$record["DESTINATION"]."</td>
<td>".$record["PRICE"]."</td>
</tr>";
}
print "</table>";
?>
Brilliant David! Thanks for the prompt and perfect help as always, it's appreciated.
Tom
David, thanks for the superfast support :-).
It works perfect apart from one thing:
The first table is cutoff correctly at the number specified (eg 25) but the second table is not cutoff and thus longer than the first table (as long as the remaining records).
A minor thing I guess but I am not very good at PHP and can't find the fix for that.
Thanks again, Tom
Hi Tom,
$items = 0; missing - corrected above...
Cheers,
David.
Hello Tom,
Have a go with something like this:
<?php
require("MagicParser.php");
global $records;
$records=array();
function myRecordHandler($record){
global $records;
$records[] = $record;
}
MagicParser_parse("filename.XML","myRecordHandler","xml|ALLITEMS/ITEM/");
function startTable()
{
print "<table width='225' class='mp-table'>";
}
function endTable()
{
print "</table>";
}
$totalItems = count($records);
$itemsPerTable = 25;
$items = 0;
startTable();
foreach($records as $record)
{
print "<tr>
<td><img src='/xml/".$record["DESTINATION"].".jpg' alt='".$record["DESTINATION"]."' title='".$record["DESTINATION"]."' height='40' width='80' /></td>
<td>".$record["DESTINATION"]."</td>
<td>".$record["PRICE"]."</td>
</tr>";
$items++;
if ($items == $itemsPerTable)
{
endTable();
if ($items < $totalItems) startTable();
$items = 0;
}
}
if ($totalItems / $itemsPerTable) endTable();
?>
Hope this helps!
Cheers,
David.
--
MagicParser.com