PHP Fill unordered List with values of Object array

noahjk

New Member
a MYSQL Query is getting me this array of objects (shortened a bit):\[code\]Array ([0] => stdClass Object ( [parentTitle] => Winner 2009 [catTitle] => Max Muster [title] => drm202 )[1] => stdClass Object ( [parentTitle] => Winner 2009 [catTitle] => Max Muster [title] => drm202 )[2] => stdClass Object ( [parentTitle] => Winner 2011 [catTitle] => Josh Frank [title] => A bird in the cage )[3] => stdClass Object ( [parentTitle] => Winner 2011 [catTitle] => Josh Frank [title] => cue & repeat )...\[/code\])How is it possible to build an unordered Html List out of this array which looks like this:\[code\]<ul id="content"> <li>Winner 2009 <ul> <li>Max Muster <ul> <li>drm202</li> </ul> </li> </ul> </li> <li>Winner 2011 <ul> <li>Josh Frank <ul> <li>A bird in the cage</li> <li>cue & repeat</li> </ul> </li> </ul> </li></ul>\[/code\]The first two objects are the same, thus in the ul the person + title should only be listed once under parent winner 2009. The winner from 2011 has two winner projects thus these two different projects should be listed under him. My approach was to have a foreach loop which fills an array\[code\] foreach ($results as $object) { // fill array $array[] = "</ul><ul><li><h2> " . $object->parentTitle . "</h2>\n</li>"; $array[] = "<li><h5>" . $object->catTitle . "</h5></li>\n"; $array[] = "<li> - " . $object->title . "</li>\n"; }\[/code\]and kick out the doubles\[code\]$array = array_unique($array);\[/code\]this way seems to be extremly unhandy and wrong.thanks for any help,tony
 
Back
Top