I have the following db table

82 is the parent of 84. 24 is the parent of 82 and 83. In php, I have a method for retrieving strings using uid.
public function fetchByUid($uid){
This will get the 7th and 6th values ββfrom the table. Now I want to get not only strings where uid is equal, but also strings in which the parent is a child of uid. For instance. 82 - the parent element 84, as well as the child element 24.
So, I came up with some recursion.
public function fetchByUidRec($uid, $data, $counter){ //set of rows by uid $db_resultSet; foreach($db_resultSet as $row){ $entry = array(); $entry['id'] = $row->id; $entry['uid'] = $row->uid; $entry['rid'] = $row->rid; $entry['layer'] = $counter; $data [] = $entry; //now I want to do the same on the child $data [] = fetchByUidRec($row->rid, $data, $counter = $counter + 1) } return $data; } public function getchByUid($uid){ $data = array(); $counter = 0; return fetchByUidRec($uid, $data, $counter) }
But this does not work at all :( I want to keep the current recursion depth in $ data ['layer']
Any ideas?
source share