I am pretty new to PHP and hope someone can help me with the following:
I have a SQL table from where I fetch data with a stored procedure. This returns the below XML. Then on my PHP page I load this XML as $objCat in order to echo it on the site with the script below.
This works so far to echo just the category groups but not for the items belonging to each group, i.e. the ones with the same category. I guess I need to nest another foreach loop here (where I have my comment below) so that it looks similar to the original XML but couldnt get this to work yet.
My XML:
<ranks>
<categories>
<categoryX>Category 1</categoryX>
<groupCount>3</groupCount>
<itemID>ID 1</itemID>
<dateX>2013-11-12</dateX>
<subjectX>Subject 11</subjectX>
<itemID>ID 2</itemID>
<dateX>2013-11-05</dateX>
<subjectX>Subject 7</subjectX>
<itemID>ID 3</itemID>
<dateX>2013-10-23</dateX>
<subjectX>Subject 2</subjectX>
</categories>
<categories>
<categoryX>Category 2</categoryX>
<groupCount>2</groupCount>
<itemID>ID 4</itemID>
<dateX>2013-11-27</dateX>
<subjectX>Subject 6</subjectX>
<itemID>ID 5</itemID>
<dateX>2013-10-30</dateX>
<subjectX>Subject 3</subjectX>
</categoryX>
</categories>
// ...
</ranks>
My PHP:
<?php
foreach ($objCat->categories as $cat) {
$catGroup = $cat->categoryX;
echo $catGroup;
// echo all itemIDs below each other where categoryX = $catGroup.
}
?>