0

I'm trying to figure out how to modify data I copy from one table into another two.

Currently I have it working so my form submits it pulls the data from 'prices' and puts it into 'pricestwo' and 'pricesthree'.

However I need to modify the data before hand to make one 10% less on price, and one 20% less on price.

<?php
$priceid = $_POST['priceid'] ; 
$name = $_POST['productname'] ;
$weight = $_POST['productweight'];
$price = $_POST['productprice'];
if(isset($_POST['updateprices'])) { 

for($i=0;$i<$count;$i++){

$sql1= mysqli_query($myConnection, "UPDATE pricestwo SET productname='$name[$i]', productweight='$weight[$i]', productprice='$pricetwo[$i]' WHERE priceid='$priceid[$i]'");

$sql2= mysqli_query($myConnection, "UPDATE pricesthree SET productname='$name[$i]', productweight='$weight[$i]', productprice='$price[$i]' WHERE priceid='$priceid[$i]'");
}
echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_product_prices.php\">";
} 
?>

This currently works to copy just the data, I've tried something like:

    $pricetwo = $price - ($price * 0.15);

to modify the data, but there are multiple rows been transferred so this just returns a 0.00 value.

Anyone have any ideas on how to do this?

Newcastlefan
  • 39
  • 3
  • 10

1 Answers1

0

Write a stored procedure for the set of queries and execute the whole in one database call. It makes a better code and improves performance.

By the way, check if you trying to modify a variable instead of array element.

CKmum
  • 641
  • 6
  • 17
  • Hi thanks for the reply, I've tired multiple ways to use the $price and $price[$i] variable, would you be able to show me an example of what you stated as I am really stuck at the moment :( – Newcastlefan Nov 07 '12 at 10:02
  • To debug, print the price variable for various combinations $price[0]" Once you get multivalue delimited string as data, also refer how to use multivalue strings inside stored procedure: http://stackoverflow.com/questions/8056507/how-to-split-comma-separated-string-inside-stored-procedure Then compute and insert as required inside the SP I'll add more soon – CKmum Nov 07 '12 at 10:09