Jump to content


Photo

Equations with integers in MYSQL?


  • Please log in to reply
5 replies to this topic

#1 kumashiru

kumashiru
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 February 2006 - 09:08 PM

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?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 February 2006 - 04:52 AM

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?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 kumashiru

kumashiru
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 February 2006 - 06:00 AM

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?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 February 2006 - 08:14 AM

Of course -- you can always retrieve data and store it in PHP variables. How do you mean?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 kumashiru

kumashiru
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 February 2006 - 05:15 PM

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.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 February 2006 - 07:51 PM

I don't understand -- just run a SELECT statement, and store the results in PHP.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users