This topic is locked
[SOLVED]

 Calculating a Value from two other MySql fields

2/3/2008 8:52:40 AM
PHPRunner General questions
author

I am sure the answer to this is very simple and it has been asked a hundred times. I am completely new to PHP and MySql but am learning slowly. I have a table which is used to enter expenses. There are two fields expenses.Cost and expenses.Quantity.
What I would like to do is to get a total from these fields on adding a record and place it into a field in the same table called logically enough expense_total.

Is this possible and if so how would I go about doing it. I have used PHPmaker which allows me to do something similar to this within a custom view, by using a select statement as follows expenses.Cost * expenses.Quantity AS extended; which creates a display field.
This obviously does not put the value into expense_total but does display the value which can then be totalled.
Any help would be very much appreciated as I really like the flexibility of PHPrunner over PHPmaker in the use of custom HTML and template modification which is not easy within phpmaker.
Sorry if this is a repeat or is so obvious that I should be shot.
Thanks Azz

E
ewold 2/3/2008

Mysql can do this for you very simple, in your sql tab, choose custom query

select all fields and add a line
Cost * Quantity AS Total
you don't need to use the table in front if you stay in the same table, because you do a select ... from expenses

3588 2/3/2008

Mysql can do this for you very simple, in your sql tab, choose custom query

select all fields and add a line
Cost * Quantity AS Total
you don't need to use the table in front if you stay in the same table, because you do a select ... from expenses


Ok thankyou, I knew it would be something simple. I feel like a total twit. Thank you again. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=25484&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />