Forum Moderators: coopster

Message Too Old, No Replies

A baffling table cell problem

         

egibberate

1:17 pm on Feb 28, 2009 (gmt 0)

10+ Year Member



Hi,
can some kind expert spot the flaw in my code please.
The problem I'm having is this;
The code produces a series of small tables depending upon how many results are returned from a search of an xml file. The first and last tables are fine, however, the intermediate tables have an extra row of blank cells at the bottom of the table.
For example, if the search returns five results, the first and fifth table will be fine, the second, third and fourth table will have a blank row of cells at the bottom of each table.
Thank you for your help, here is the 'defective' code!

<?php
echo ('<table class="tablea">');
$q=$_GET["q"];$xmlDoc = new DOMDocument();
$xmlDoc->load("book.xml");
$x=$xmlDoc->getElementsByTagName('title');
for ($i=0; $i<=$x->length-1; $i++)
{
//Process only element nodes
if ($x->item($i)->nodeType==1)
{
if ($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}
$cd=($y->childNodes);for ($i=0;$i<$cd->length;$i++)
{
echo($i);
//Process only element nodes
if ($cd->item($i)->nodeType==1)
{
if($i==7)
echo ('</table><br /><table class="tableb">');
echo('<tr><td>');

if($i%10==7 and $i>7)
{
echo("</table><br /><table class='tableb'>");
if($i%10==8 and $i>7)
echo("</table><br /><table class='tableb'>");
echo('<tr><td>');

}
echo($cd->item($i)->childNodes->item(0)->nodeValue);
}
}
echo ('</table>');
?>

It's also worth mentioning that as you can see I echo'd the value of $i onto my page so that I could temporarily easily count the results, strangely, it doesn't start the count at the first value of the first cell in the first table, it counts '0' then '1' ABOVE the first table then continues the count at '2' in the first cell of the first table?!

walrus

5:21 pm on Feb 28, 2009 (gmt 0)

10+ Year Member



No closing </tr></td> ?