Jump to content

From one table to another


rfrunk

Recommended Posts

Just need what for some of you should be easy.
Trying a mod on prestashop and just need the following to work.
It works fine if there is just one row of data (one product). If there are more than one the first row works fine but the second and susequent rows fail.

$sql = "SELECT * FROM ps_cart_product Where id_cart = '$cartid'"; 
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
  $product_instructions = $row ['instructions'];
  $product_request = $row ['request'];
}

$db = Db::getInstance();
mysql_query("UPDATE `store`.`ps_order_detail` 
SET `product_instructions` = '$product_instructions',`product_request` = '$product_request' 
WHERE `ps_order_detail`.`id_order` = '$id_order' 
AND `ps_order_detail`.`product_name` like '%$product_instructions%'");

Link to comment
Share on other sites

  • 2 weeks later...

It seems you have the curly braces in the wrong place, causing the $product_instructions and $product_request to be overwritten with each subsequent loop. Try:

$sql = "SELECT * FROM ps_cart_product Where id_cart = '$cartid'"; 
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
  $product_instructions = $row ['instructions'];
  $product_request = $row ['request'];

  $db = Db::getInstance();
mysql_query("UPDATE `store`.`ps_order_detail` 
SET `product_instructions` = '$product_instructions',`product_request` = '$product_request' 
WHERE `ps_order_detail`.`id_order` = '$id_order' 
AND `ps_order_detail`.`product_name` like '%$product_instructions%'");
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...