Jump to content

Equal To Update ( More Help )


jj20051

Recommended Posts

I Do Have Two More Requests If You Would Like To Help.

 

1. I Need To Some How Take 15% Off All Price Values In A Table. The Table Name Is checkout .

 

2. i have made a script to copy one of the values in a table to another table as shown bellow. but the problem is when they copy the id stays with them. is there any way to have it create a new id?

 

mysql_query("INSERT INTO checkout (id,name,barcode,price,quantity) SELECT id,name,barcode,price,quantity FROM products where barcode='$barcode1'")

or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/114490-equal-to-update-more-help/
Share on other sites

mysql_query("INSERT INTO checkout (id,name,barcode,price,quantity) SELECT id,name,barcode,price,quantity FROM products where barcode='$barcode1'")
or die(mysql_error());

 

Try this,but make sure that id is primary key and auto increment for checkout table.

 

mysql_query("INSERT INTO checkout (name,barcode,price,quantity) SELECT name,barcode,price,quantity FROM products where barcode='$barcode1'")
or die(mysql_error());

You should have just waited for a reply in the other topic instead of starting a new one...

 

$query = mysql_query("SELECT * FROM `checkout`");

$oldPrices = array();
while($r = mysql_fetch_array($query)){
array_push($oldPrices,$r['price']);
}

$newPrices = array();
$discount = 15; //in percent

for($i = 0; $i < count($oldPrices); $i++){
array_push($newPrices,$oldPrices[$i]-($oldPrices[$i] * ($discount/100)));

echo "It was $".$oldPrices[$i]." but now it is $".$oldPrices[$i]-($oldPrices[$i] * ($discount/100))."!";
}

 

And for question number 2 just try removing the id from both the statements, so its just 'name,barcode,price,quantity'.

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.