PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm after a bit of help with summing up some arrays, to build a Quote for a Project.
- Project_ID
- Job_ID (repeated for each Project_ID)
- Task_ID (repeated for each Job_ID)
Each Task_ID has it's own cost, so what I need to do is sum up the Tasks, to give a total for Job and likewise I need to sum up the Job totals to give a Project total.
Hopefully this will give you some idea as to what I have in my database:
Project_1
Job_1 (fk_proj_id=1)
Task_1 (fk_job_id=1)
Task_1_cost = £500
Task_2 (fk_job_id=1)
Task_2_cost = £500
Job 2 (fk_proj_id=1000)
Task_2 (fk_job_id=2)
Task_2_cost = £900
The result I'm after is:
Job_1 = £1000
Job_2 = £900
Project_1 = £1900
It's going to be messy if you have actually stored that pound sign in the db. If not, then you are better off using the SQL sum() function:
[text]SELECT sum(cost) from table_name WHERE job_id = 1[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Each task has a calculated cost, what I'm after is a job_total which is a sum of the tasks for that job, then a project total which is a sum of the job_totals for that project . .. .if that makes sense?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
So it is adding Job 1 total to Job 2 total (which is the wrong bit), then summing up both totals (which is what it should do) to give the Project total.