Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Updating and Deleting Records Review and Next Steps

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Showing associated project in the task list

Hi everyone.

:) So I've just finished the project (give or take one or 2 bugs) and I've started out trying a 1 or 2 additions of my own.

One of the things that bugged me about this project is how when you look at the task list, there's no indication of which project the task is currently linked to, (unless you click on that task).

So I thought I'd have a go at getting a non clickable reference to the project on the list.

I managed to get this to display what I presume is the project ID. with $task['project_id'] .`

<?php   

    foreach (get_task_list() as $task) {
        //return title of task
        echo "<li><a href='task.php?id=" . $task['task_id'] . "'>" .  $task['title'] . "</a> (" . $task['project_id']  . ")";

                            echo "<form method = 'post' action='task_list.php' onsubmit=\"return confirm('Are you sure you want to delete this project?');\">";
                            echo "<input type = 'hidden' value= '" . $task['task_id']  . "' name='delete' />";
                            echo "<input type = 'submit' class = 'button--delete' value='Delete' />";
                            echo "</form>";
                            echo "</li>";
                        }

                    ?>

But the data that I need to pull belongs in the other table. How can I get a reference to the column that I need?

I've tried adding a nested foreach loop like this

<?php   

    foreach (get_task_list() as $task) {
        //return title of task
        echo "<li><a href='task.php?id=" . $task['task_id'] . "'>" .  $task['title'] . "</a> (" . $task['project_id'] . ' ' . 

        foreach(get_project_list() as $project {
            echo $project['title']

        }

        . ")";

        echo "<form method = 'post' action='task_list.php' onsubmit=\"return confirm('Are you sure you want to delete this project?');\">";
        echo "<input type = 'hidden' value= '" . $task['task_id']  . "' name='delete' />";
        echo "<input type = 'submit' class = 'button--delete' value='Delete' />";
        echo "</form>";
        echo "</li>";
    }
?>

I'm sure I've seen something like this before when a loop can exist inside another but I'm out of ideas now. :-)