my xml looks likes this
<?xml version="1.0" encoding="utf-8"?>
<personnel>
<person id='1'>
<person_name>John</person_name>
<person_lastname>Doe</person_lastname>
<codes>
<code_number>A132</code_number>
<code_number>B123</code_number>
<code_number>C123</code_number>
</codes>
<person_code>
<code_title>Developer</requisition_title>
<code_relocation>15~25%</code_relocation>
</person_code>
</person>
</personnel>
i wanted to make a table(using PHP) which rows are dependent by the number of "code_number" under "codes". so that the table should look like this:
Person ID | Person Name| Person LastName | Code Numbers
_________________________________________________________
1| John| Doe| A123
_________________________________________________________
1| John| Doe| B123
_________________________________________________________
1| John| Doe| C123
my currrent PHP script which i got from other stackoverflow examples is:
<?php
$dom = new DOMDocument();
$dom->load('person.xml');
$xpath = new DOMXpath($dom);
echo <<<EOF <table border="1" cellspacing="2" cellpadding="2"> <tr>
<th>Person ID</th>
<th>Person Name</th>
<th>Person LastName </th>
<th>Code Numbers</th>
</tr>
EOF;
$persons = $xpath->evaluate('//person');
foreach ($persons as $person) {
echo '<tr>', "
";
echo '<td>', htmlspecialchars($xpath->evaluate('string(./id)', $person)), '</td>', "
";
echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_name)', $person)), '</td>', "
";
echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_lastname)', $person)), '</td>', "
";
$codes = array();
foreach ($xpath->evaluate('./codes/code_number', $person) as $code_number) {
$codes[] = $code_number->nodeValue;
}
echo '<td>'.htmlspecialchars(implode(', ', $codes)).'</td>', "
";
echo '</tr>', "
"; } echo '</table>';
?>
however the output of this is based on how many "person id" is on the XML file. thanks for you help!
</div>