jj20051 Posted July 13, 2008 Share Posted July 13, 2008 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 More sharing options...
mmarif4u Posted July 13, 2008 Share Posted July 13, 2008 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()); Link to comment https://forums.phpfreaks.com/topic/114490-equal-to-update-more-help/#findComment-588731 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 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'. Link to comment https://forums.phpfreaks.com/topic/114490-equal-to-update-more-help/#findComment-588732 Share on other sites More sharing options...
jj20051 Posted July 13, 2008 Author Share Posted July 13, 2008 Thank You and Sorry, but I Didn't Think You Would Catch It. Link to comment https://forums.phpfreaks.com/topic/114490-equal-to-update-more-help/#findComment-588736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.