How can i add two colum.
i have a table called scores with colum ca, exam and total. every tin is working fine. i want to be able to add the database vaue of ca and exam (ca + exam) and display the output in the total colum pls help
Hello,
Quickest solution would be to put sum in SQL and make total column. After that you can use that column in grid to display sum data.
e.g.
$g->select_command = "SELECT ca,exam, ca+exam as total FROM mytable";
later in grid code, you can define:
$col["name"] = "total";
Hi Abu,
i i had implemented this suggestion previously as such
$g->select_command = "SELECT sn, stud_name, stud_id, ca, exam, grade, remark, (ca+exam) as total FROM scores
the problem is that when i display the addition works
eg
ca exam total
10 30 40
the sql code above displays. But when i change the values
ca exam total
15 30 40
after refresh i get this
ca exam total
15 30 45
which is correct.
but the value for 'total' in the database table did not change automatically. Is there anyway i can automatically perform the addition between ca+exam and it update in the 'total' column of the database table automatically
plseas help me out
thanks
Hello,
Option 1) Use mysql trigger to perform addition on update/insert and save in that field. See mysql triggers help for more.
Option 2) You can have custom events in phpgrid (on_update / on_insert) where you can perform the work and set in total field to be saved in db. Custom events are available in licensed version.