the calculation part is just for example, i think you must make that part of your own .
then select the two amonts from the table,
<?
include("connect.php");
$user_a=1;
$user_b=2;
$sql="SELECT amont_id, amont_a, amont_b FROM amonts WHERE user_a=$user_a AND user_b=$user_b LIMIT 1";
$result=mysql_query($sql);
if(mysql_num_rows($result)>0) //if there is a row with these parameters,
{
$row=mysql_fetch_assoc($result)
$user_a_amont=row["amont_a"];
$user_b_amont=row["amont_b"]
$amont_id=$row["amont_id"];
//and here you can put the calculations for the new
//for example:
$user_a_new_amont=$user_a_amont-($user_b_amont/4);
$user_b_new_amont=$user_b_amont-($user_a_amont/4);
//AND you could update the table with the new values
$sql="UPDATE SET amonts SET amont_a='$user_a_new_amont', amont_b='$user_b_new_amont'
WHERE amont_id=$amont_id";
$result=mysql_query($sql);
if($result)
print 'UPDATED SUCCESFULLY';
else
print 'UPDATED FAILED';
}
?>
IMP_TWI;10891103 wrote:Alright.. I am very new to php and have had a problem with a new script i'm trying to write..
So I have 2 fields in the database lets call it A, and B which both have different amounts in it, A has the amount of 30( units ) and B has a amount of 10 ( units ). I need help making a script where when they click "Submit" It'll total up the total up the amount they have and then lets say "If person has A, total damage amount is = 3 (value of A per unit) x 30 (total amount of A'units' ) and same with B" then divide total by 1/4..
The question is how would I put that into a php script? any help would be very useful.. I'm trying to learn how to do these things that I'm not use to which is why I'm posting here asking for help 🙂