CodeIgniter Forums
Repeating Tasks Without Repeating Projects - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Repeating Tasks Without Repeating Projects (/thread-22404.html)



Repeating Tasks Without Repeating Projects - El Forum - 09-08-2009

[eluser]jshultz[/eluser]
Here's the link to the code: http://stikked.com/view/8550586

It's repeating the project over and over, and I would like for it to just show the project once and then the associated tasks below it.

I'm just not sure how to accomplish that though.

Would there be a way to loop through the join data to just show the tasks without reprinting the project name?


Repeating Tasks Without Repeating Projects - El Forum - 09-08-2009

[eluser]garymardell[/eluser]
You will need to pass through a limit $this->db->limit(1);
Also seems your get tasks by id has no id to work with.

That function tasksByProjectId() is always going to return all the projects.


Repeating Tasks Without Repeating Projects - El Forum - 09-08-2009

[eluser]jshultz[/eluser]
How would that ($this->db->limit(1)Wink work? I understand what it does, but I want to cycle through all the projects and their associated tasks. I would just like the tasks to be listed under each project without it repeating the same project over and over.

In other words I want:

project
-task
-task
project 2
-task
project 3
project 4
-task
-task
-task

instead, i'm getting
project
-task
project
-task
project 2
etc.
etc.
etc.


Repeating Tasks Without Repeating Projects - El Forum - 09-08-2009

[eluser]garymardell[/eluser]
Oh sorry, i thought you meant that you just wanted to show one project. My bad.
You will probably have to create a temporary array using the id as the array index.


Repeating Tasks Without Repeating Projects - El Forum - 09-08-2009

[eluser]jshultz[/eluser]
that's exactly what I ended up doing and it worked. thanks. Smile

Here's the code thanks to ignitedcoding on the IRC channel:

Code:
<?php $currentProjectID = NULL; ?>        
<?php foreach ($projectPlusTasks as $row): ?>
        <?php if ( $currentProjectID != $row->projectid ): ?>
        <tr>
            <td>
                <strong>Project:</strong>
                &lt;?= $row->projectid?&gt;
            </td>
            <td>
                &lt;?= $row->project_name?&gt;
            </td>
            <td>
                &lt;?= $row->p_due_date?&gt;
            </td>
            <td>
            </td>
        </tr>
        &lt;?php endif;?&gt;
        <tr>
            <td>
                <strong>Task:</strong>
                &lt;?= $row->taskid?&gt;
            </td>
            <td>
                &lt;?= $row->task?&gt;
            </td>
            <td>
                &lt;?= $row->t_due_date?&gt;
            </td>
            <td>
            </td>
        </tr>
        &lt;?php $currentProjectID = $row->projectid; ?&gt;
        &lt;?php endforeach; ?&gt;