lfernando Posted November 25, 2011 Share Posted November 25, 2011 So I've been trying to do this for days now and i'm at my witts end. I hope someone has an easier way!! I have a table with "tasks" and "subtasks", like this: task_id Title Owner parent_task_id 1 house chores ana 0 2 groceries ana 0 3 homework pete 0 4 vacuum adam 1 5 clean windows mike 1 6 vacum carpet adam 4 As you can see... - Tasks 4 and 5 are children of task 1. - Task 6 is a child of task 4, hence a grandchild of task 1. - Task 2 and 3 dont have any subtasks. - Tasks and subtasks dont always have the same owner So I need to display this as follows: * House Choures * vacum * vacum carpet * clean windows * Groceries * Homework So I can query the DB and put all tasks into an array ($tasks[]), then i build the following code: function build_tasks($tasks,$parent_id) { if(is_array($tasks)) { foreach($tasks as$task) { if($task['parent_id']==$parent_id) { echo "<ul> * ".$task['title']."</ul>"; } build_tasks($task['task_id'], ($table_width-2), $tasks, $link); } } } so to build the table I start with build_tasks($tasks, 0). That way it will start building parents and subtasks, starting with the ones with parent task id =0. The problem is when i filter $tasks to only show tasks by "adam". Adam doesnt have any taskas with parent_task_id=0, because all his tasks are under someone else's, so they never show up. Please, please, PLEASE help! Link to comment https://forums.phpfreaks.com/topic/251786-taska-and-subtasks/ Share on other sites More sharing options...
Adam Posted November 25, 2011 Share Posted November 25, 2011 You need to perform a multidimensional array_search(). Somebody posted their effort at a custom function for it on the manual. Link to comment https://forums.phpfreaks.com/topic/251786-taska-and-subtasks/#findComment-1291126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.