Jump to content

Multiply/Addition php mysql help?


jurass1c

Recommended Posts

Heja

 

I have a MySQL database which contains information of members and the current balance of there accounts (eg: $1000) it also shows there current gain (eg: 1.2%) what i have been doing is individually updating each clients percent and balance. What i'm trying to work out is how to add a percent gain for the week and both the percent and balance of the clients are updated according to the submitted gain for example:

 

Client 1 has $1,000 and has a current gain of 1.5%

Client 2 has $,2000 and has a current gain of 2.5%

 

I want to update both clients by 1.5% and then both clients be updated like so:

 

Client 1 would now have $1,010.50 and now has a gain of 3.0%

Client 2 would now have $2,020.50 and now has a gain of 4.0%

 

I was looking around and could find much information on the internet or exactly has this can be achieved so i started to work on a addition and try atleast add the % however it dont go accordingly, i suppose im very rusty at my php. I started working around something  like this:

 

mysql_select_db('mem') or trigger_error("SQL", E_USER_ERROR);

$a1 = mysql_query("SELECT profits FROM account"); 

$a= $a1; 
$b=$b1;    /* html <input type="text" name="b1" id="b1"> the % i want to update*/


$add=($a+$b);

$sql = "UPDATE mem SET balance = balance +'$add'";  


if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }

 

This obviously does not work but it could possibly give you a better understanding of maybe what im trying to do here. Any help would be appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/
Share on other sites

What arn't you getting?

 

$percent reffers to your $b

for a numeric example

$qry = UPDATE mem SET balance = ( balance + (balance * (1.5 / 100)) ) WHERE balance = 1000.00

Do please remeber the WHERE or you will update every balance to the same value (never handy).

Archived

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

×
×
  • Create New...

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.