Up vote 0 down vote favorite share g+ share fb share tw.
I have data in a MySQL table, (called info), like this: _______________________ id | text | parent | 1 | a | NULL | 2 | be | 1 | 3 | c | 1 | 4 | d | 2 | ----------------------- (id is auto incrementing) I want to display this data in PHP, like this: >a (ID 1) >>b(ID 2) >>>d (ID 4, parent 2) >>c (ID 3) I have attempted different methods, but I can't seem to be able to get them to work either way. I know I need a recursive function, but how would I do this? A simple pointer would be enough; thanks.
Php threaded-comments link|improve this question asked Jun 21 '11 at 19:07Iyra Gaura1.
Well as you are getting the table: $parents = array(); $children = array(); while($row = ...){ if($row'parent' == null){ $parents = array ('id' => $row'id', 'text' => $row'text') } else{ if(!isset($children$row'parent')) $children$row'parent' = array(); $children$row'parent' = array ('id' => $row'id', 'text' => $row'text') } } Iterate using this function: function displayChildren($array, $id, $char = ">"){ foreach($array as $ch){ if($ch'id' == $id) echo "$char {$ch'text'} (ID {$ch'id'})" } }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.