PDA

View Full Version : mysql capable column calculations? how?


sad69
03-25-2004, 12:27 AM
Hey all,

I've got a question in regard to MySQL. Consider this example:
3 columns: net_amt, increase, gross_amt.

Can you make it so that if you insert a new row and provide net_amt and increase (where increase is a percentage), it will automatically calculate the gross?

so let:
net_amt = 5000
increase = 38

then:
gross = 6900

[5000 * 1.38 = 6900]

I'm not using PHP to insert these values, but I will be using phpMyAdmin to insert rows into this table and update this table. I'm just wondering if MySQL gave you that ability.

I suppose I could create a page that would do the above in PHP, but if MySQL will do it for me, that would save me some time!

So if you know that it can be done (or if it can't be done..), please let me know!

Thanks,
Sadiq.

raf
03-25-2004, 09:44 AM
I don't see how that would be possible in mySQL. You need a stored procedure for that, which will only be supported from v5.0.

But why do you wan't to do this through phpmyadmin ? I don't see how this could be qiucker then creating a webform where you enter these two values.

sad69
03-25-2004, 07:38 PM
Because I'm a lazy-a**...

No problem, I don't know too much about databases in that respect -- but thanks for 'defining' the term stored procedure. I heard of them but wasn't sure what they would actually be used for..

Perhaps I can wait it out a while till v5.0 is released, but if worse comes to worst, I'll create that webform.

Thanks raf,
Sadiq.