I have a sql table in my database "accounts" whose structure looks like this.
ItemNo CostPrice SellingPrice Discount(10%) Price(INR)
100 $100 $150 $135 Rs.7425
101 $200 $250 $225 Rs.10395
102 $150 $200 $180 Rs.7920
103 $500 $550 $495 Rs.25245
Here each column is dependent on the previous one.
SellingPrice = CostPrice + 50
Discount = SellingPrice + (0.1 * SellingPrice)
Price(INR) = SellingPrice * ($_Conversion_rate_to_Rs)
I need to calculate the SellingPrice and update it in the table. Then I calculate the Discount and update the table Then I calculate the Price(INR) and update the table.
I am trying the following code but it doesnt seem to be working.
$i = 0;
foreach($item_no as $item ){
mysql_query("UPDATE accounts SET SellingPrice = CostPrice + 50 WHERE item_no = '$item[$i]'") or die(mysql_error());
++$i;
}
Now after updating the SellingPrice I need to calculate the discount and update the database.
$i = 0;
foreach($item_no as $item ){
mysql_query("UPDATE accounts SET Discount = SellingPrice + (0.1 * SellingPrice) WHERE item_no = '$item[$i]'") or die(mysql_error());
++$i;
}
And so on..
My doubt may be quite simple but I tried a lot and couldn find a correct solution.
Can I know my mistakes and the correct solution ?