Jump to content

Archived

This topic is now archived and is closed to further replies.

kumashiru

Equations with integers in MYSQL?

Recommended Posts

Is there anyway using php to add, multiply, subtract, etc, integer inside a mysql table?

example..

id|name|int1|int2|int3
[!--sizeo:2--][span style=\"font-size:10pt;line-height:100%\"][!--/sizeo--]1| john | 3 | 2 | 4
2| mary | 5 | 3 | 4[!--sizec--][/span][!--/sizec--]

and i need to subtract john, int1, from mary, int4 and display it for the user to see (display, but not change the data inside the table)

all the numbers are predefined in the table, and there's noway for the user to change them.

any help?

Share this post


Link to post
Share on other sites
Huh? The MySQL parser can do math (e.g. int1-int4), but it won't work _across_ rows. You'd have to do some fancy joins for that... it'll get complicated. Maybe you can explain further?

Share this post


Link to post
Share on other sites
hmm.. i see it can get complicated.

well then, is taking data from mysql table and turning it into a php $variable possible without using post/submit?

Share this post


Link to post
Share on other sites
Of course -- you can always retrieve data and store it in PHP variables. How do you mean?

Share this post


Link to post
Share on other sites
Using the (badly aligned) example above, store int2 from id1, and int2 from id2 into $variable1 and $variable2 then use that to add/multiply/whatever?

how would i go about putting them into variables?

I know I can do this with post/submit deal, but i'm trying to avoid using that.

Share this post


Link to post
Share on other sites
I don't understand -- just run a SELECT statement, and store the results in PHP.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.