Page 1 of 1
Adding Values, how is it done?
Posted: Tue Jul 01, 2008 11:10 am
by nitation
Hello people,
I can insert a value for a field named amount in my database, what i wanna do now is to add another value and it sum it up. My question is how do i go about it? do i insert a new value in the amount field on another row and add it? if yes, how do i do that in php.
Thanks in advance
Re: Adding Values, how is it done?
Posted: Tue Jul 01, 2008 11:21 am
by jaoudestudios
I am not totally sure what you mean, can you paste your code?
There are various ways: you could add another row and then when you want a total, sum up all the rows; or you can take the value in the field and add to it and then update that row with the new total value.
It depends on what you are using it for.
Re: Adding Values, how is it done?
Posted: Tue Jul 01, 2008 11:45 am
by nitation
Thank you for your reply.
I tot of using this query and it worked.
"UPDATE Table SET Amount = Amount + $newAmount";
regards
Re: Adding Values, how is it done?
Posted: Tue Jul 01, 2008 12:59 pm
by jaoudestudios
it works?
do you still need help?
I would recommend not parsing the php variables, maybe use this instead:
$q = "UPDATE table SET amount = 'amout + ".$newamount."'";
are you sure it worked? you need to add a WHERE onto the mysql query, otherwise it does not know which entry to update, so it will do all the entries, or is that what you want it to do?
Re: Adding Values, how is it done?
Posted: Tue Jul 01, 2008 1:05 pm
by nitation
I have included the where clause. Please tell why the dot(.) before and after the variable .$newamount.
Thanks in advance
Re: Adding Values, how is it done?
Posted: Tue Jul 01, 2008 1:08 pm
by jaoudestudios
the dot (.) is to append/concat the php variable to the rest of the string.