jurass1c Posted April 7, 2011 Share Posted April 7, 2011 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 More sharing options...
jurass1c Posted April 13, 2011 Author Share Posted April 13, 2011 Bump.... Any idea's here? Link to comment https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/#findComment-1200933 Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2011 Share Posted April 13, 2011 The query would end up like this, where $percent is the percentage amount from your form data. UPDATE mem SET balance = ( balance + (balance * ($percent / 100)) ) Link to comment https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/#findComment-1200970 Share on other sites More sharing options...
jurass1c Posted April 13, 2011 Author Share Posted April 13, 2011 I see, could i maybe just get a rough example i'm still a little lost. Thanks heaps for taking the time to help me out, ive been stuck on this for a while. Link to comment https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/#findComment-1201103 Share on other sites More sharing options...
jurass1c Posted April 18, 2011 Author Share Posted April 18, 2011 bump... anyone? Link to comment https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/#findComment-1202948 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2011 Share Posted April 18, 2011 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). Link to comment https://forums.phpfreaks.com/topic/232949-multiplyaddition-php-mysql-help/#findComment-1202975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.