Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Adding values in a mysql database

  • 01-03-2006 5:52pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    I have a table, tbl_hours, which saves hours spent on a specific task into the field hours_spent, and also has a unique id hours_task_id. I want to create a page that will sum up the total hours for a specific task based on the hours_task_id.

    So I will have a page listing existing tasks, from tbl_tasks, and when i click on a task it shows me a page that will give me details on the task, which i can select from tbl_task, and the total hours summed from the hours_spent field where the task_id = hours_task_id.

    Am I making sense? :D


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    SELECT SUM(hours_spent) from tbl_hours WHERE task_id = hours_task_id GROUP BY hours_task_id

    Should work.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    And how would I print that in the table? I.e. the task name is printed out with:

    print("<td> ".$row."</td>");

    but how do I print the results of the sum() function?


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Yeah, forgot that. It can be a bit finnicky. Easier to write

    SELECT SUM(hours_spent) as total_hours_spent from tbl_hours WHERE task_id = hours_task_id GROUP BY hours_task_id

    And then just use $row to output it.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Works a charm, cheers!


Advertisement