I have a table called tasks which contains a number of tasks for projects (for example 6 tasks are related to one project). On 'view projects' page, you can see the projects, and I have one column which needs to display the number of tasks associated with the project (in that particular row).
So basically, I need a query or PHP calculation that can add up the number of tasks for the project and then display this number dynamically! So far I have this running correctly with:
SELECT (SELECT count(*) FROM tasks where tasks.project_id = projects.projectid) as num_tasks, projects.projectname, projects.projectid
FROM projects
This displays the total number of tasks for a project in 'num_tasks' row, and then I have simply called this into the table row. HOWEVER, this displays all tasks totals for each project, and not only for the project in the row. Plus, each user is associated with a project (I have usersprojects table to split the many-to-many) so I want the task totals displayed only to be relevant to the current user viewing (of whom is associated with the projects obviously!).
Without the above query, I simply have the projects displaying that the user is associated with. However, I just need something that displays the task totals for each of THEIR projects! Thanks for any help!