[solved] Making a parentlist of id - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: [solved] Making a parentlist of id (/showthread.php?tid=66803) |
[solved] Making a parentlist of id - wolfgang1983 - 12-05-2016 I have a forum table. I need to make a parent list of all my pids. Lets say if I need to make parentlist for fid 36 As shown in image below Then then it should return PID numbers only 35, 34, 1 not to return 0 if pid is 0 Example I have tried PHP Code: public function make_parent_list() { Question How can I get it to properly make the parentlist. Can not seem to return 35, 34, 1 if fid 36 RE: Making a parentlist of id - InsiteFX - 12-05-2016 Revisiting the multilevel menu in PHP with some additional code RE: Making a parentlist of id - wolfgang1983 - 12-05-2016 (12-05-2016, 04:01 AM)InsiteFX Wrote: Revisiting the multilevel menu in PHP with some additional code Don't think is what I am after to not need to create a menu. RE: Making a parentlist of id - Wouter60 - 12-05-2016 Try making a recursive function. Maybe this will work: PHP Code: private function get_parents($fid, &$parents = array()) RE: Making a parentlist of id - wolfgang1983 - 12-05-2016 I now have tried this PHP Code: public function make_parent_list($fid) { But the implode throws error here Code: A PHP Error was encountered Echo out put is 34,Array PHP Code: $results = $this->make_parent_list('36'); RE: Making a parentlist of id - Paradinight - 12-05-2016 (12-05-2016, 08:53 PM)wolfgang1983 Wrote: I now have tried this PHP Code: string implode ( string $glue , array $pieces ) 1. $result is a int or an array 2. you forgot to escape $fid 3. http://stackoverflow.com/questions/29384548/php-how-to-build-tree-structure-list RE: Making a parentlist of id - wolfgang1983 - 12-05-2016 Solution found PHP Code: function getCategoriesByParentId($fid) { And PHP Code: $all_categories = $this->getCategoriesByParentId(36); |