Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

adding up numbers & update database

Community Beginner ,
Sep 25, 2006 Sep 25, 2006
Hey all, I'm using PHP/MySQL & Dreamweaver 8 with Interakt MX Kollektion, and I ran into something I could use some help with. After a lot of googling I finally found out how to add up numbers and show the result.

My question is:
Number 1 + Number 2 = Number 3

What do I do to store 'Number 3' in the DB?

Any help would be very very very welcome. Been going crazy over this for a long time now.
TOPICS
Server side applications
291
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 26, 2006 Sep 26, 2006
ZwartWitVlindertje wrote:
> $sql=mysql_query ("UPDATE User SET userMoney = userCredits + '$userMoney'
> WHERE userID = '$userID'");
>
> Something like that? =/

No. If you want to add userMoney to userCredits and reset userCredits to
0, it would look like this:

$sql = "UPDATE User SET userMoney = userMoney+userCredits, userCredits =
0 WHERE userID = $userID";
mysql_query($sql);

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/...
Translate
LEGEND ,
Sep 25, 2006 Sep 25, 2006
Basically you write an update statement that picks up the calculated Number
3 and stores it in the approprate field in the DB.

--
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver

Valleybiz Internet Design
www.valleybiz.net

"ZwartWitVlindertje" <webforumsuser@macromedia.com> wrote in message
news:ef9r2u$gks$1@forums.macromedia.com...
> Hey all, I'm using PHP/MySQL & Dreamweaver 8 with Interakt MX Kollektion,
> and I
> ran into something I could use some help with. After a lot of googling I
> finally found out how to add up numbers and show the result.
>
> My question is:
> Number 1 + Number 2 = Number 3
>
> What do I do to store 'Number 3' in the DB?
>
> Any help would be very very very welcome. Been going crazy over this for a
> long time now.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2006 Sep 26, 2006
ZwartWitVlindertje wrote:
> My question is:
> Number 1 + Number 2 = Number 3
>
> What do I do to store 'Number 3' in the DB?

If numbers 1 and 2 are already stored in the database, you don't need to
store number 3. In fact, you shouldn't. A general principle of databases
is that data should be stored at its basic level, and you should never
store the result of a calculation derived from numbers already stored in
the database.

Why? Let's say your database stores prices, and everything is subject to
10% sales tax. If you create another column for the tax-inclusive price,
you will have to update every single record in the database if the tax
rate goes up to 15%. However, by storing the price on its own, you can
always calculate the tax-inclusive price either in PHP or in your SQL query.

SELECT price * 110 AS tax_inc FROM price_table

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 26, 2006 Sep 26, 2006
Guess I should have explained this, what I want to do is:

Money + Gamecredits = Money (updated)

And the GameCredits should be put back at 0.

I have been trying for so long now, different ways, asked around on other forums and still not working... What would the update statement look like?

$sql=mysql_query ("UPDATE User SET userMoney = userCredits + '$userMoney' WHERE userID = '$userID'");

Something like that? =/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2006 Sep 26, 2006
LATEST
ZwartWitVlindertje wrote:
> $sql=mysql_query ("UPDATE User SET userMoney = userCredits + '$userMoney'
> WHERE userID = '$userID'");
>
> Something like that? =/

No. If you want to add userMoney to userCredits and reset userCredits to
0, it would look like this:

$sql = "UPDATE User SET userMoney = userMoney+userCredits, userCredits =
0 WHERE userID = $userID";
mysql_query($sql);

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines