Jump to content

Taska and Subtasks?


lfernando

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.