Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed CRUD Operations with PHP!
You have completed CRUD Operations with PHP!
Preview
Now that we've completed adding projects, we're going to perform those same processes for adding tasks. Reading the task table and populating our task list.
$sql = 'SELECT tasks.*, projects.title as project FROM tasks JOIN projects ON tasks.project_id = projects.project_id';
Course
Querying Relational Databases: Joining Table Data with SQL
Additional Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now that we've completed adding projects,
0:00
we're going to perform those
same processes for adding tasks.
0:02
Reading the task table and
populating our task list, accepting and
0:07
filtering user data, and finally,
writing that data to the database.
0:12
Once again,
0:17
we'll start with reading the data we
want to show on the task list page.
0:17
Back in functions.php,
let's duplicate the get_project_list.
0:23
And we'll name it get_task_list.
0:31
The SQL statement is going to
be a little more complicated, so
0:35
let's move it out of the query method.
0:38
For this select,
we want to pull all the task
0:50
Information so we use SELECT * FROM tasks.
0:55
But we also want to pull
the project title, so
1:00
we're going to join these tables.
1:04
Let's add this on a second line,
1:06
JOIN projects ON.
1:10
Since the task and
project tables both have project IDs,
1:15
we need to specify which
table we're talking about,
1:19
tasks.project_id =
1:22
projects.project_id.
1:27
We also need to edit our SELECT.
1:33
Instead of just saying select all,
we want to add tasks.all.
1:36
We also want to pull the project title,
but since the tasks table and
1:43
the projects table both
have fields named title,
1:47
we need to specify projects.title and
1:51
then the keyword as followed
by an alias or new name.
1:55
We want to use project.
2:01
Now, we can use this function for
our task list.
2:05
Go to the project_list and
copy this foreach loop.
2:09
Then open tasks_list.
2:14
In our unordered list,
we're going to paste and
2:18
change get_project_list to get_task_list.
2:21
Great job.
2:25
Let's take a look at
this page in the browser.
2:26
Now, our Task List page shows
a list of all our tasks.
2:31
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up