General Report
Explore how to generate detailed reports in a PHP CRUD application by fetching and joining tasks with projects. Understand how to dynamically display tasks, calculate subtotals and totals, and organize data efficiently using SQL joins and PHP loops for clear project-based task summaries.
We'll cover the following...
We need to get all the information about the tasks with totals from the database. For this, we’ll create the reports.php file in both the controllers and the views folders.
Model
In our model.php file, we’ll need to modify the get_all_tasks() function. Don’t forget that the tasks and projects tables are in a relationship. Therefore, we also need a way to select corresponding projects along with the tasks. One way to do this is by using the SQL INNER JOIN clause.
We’ll replace the $sql = 'SELECT * FROM tasks ORDER BY date_task line with:
$sql = 'SELECT t.*, ...