Insert Value From One Table to Another on Update MySql, PHP -


i wondering if there way take 1 value column in table , add column in table.

the scenario: have table (shopping_cart). stores of customers shopping cart items in columns customerid, pid, price, status (status can "in_cart" means added , "open" means has been paid , ready processed , shipped). have table (products). stores product information in columns pid, price,weight`. when customers place item in shopping cart not capture price. prices can change daily if add today, when come tomorrow price may increase or decrease in shopping cart. when customer checks out , payment confirmed, trying grab price in (products) table products.pid = shopping_cart.pid , apply price shopping_cart.price lock in final price since customer has paid it. ideas? got set change items customers cart "open" little lost on getting script grab value 1 table , applying table. below php script changing lines "in_cart" "open".

if($the_function=="close_lines"){      $cart_close_session_id = $_get['close_session_id'];      $response = array();       require_once __dir__ . '/db_connect.php';      //connect db     $db = new db_connect();      $result = mysql_query("update shopping_cart set status = 'open' sessionid '$cart_close_session_id' , status 'in_cart'");      if ($result) {         $response["close_success"] = 1;  //grab price "products table" , update shopping_cart       }else{         $response["close_success"] = 0;     }     echo json_encode($response); } 

assuming have *shopping_cart* table price , product_id column, can update price of products table, this:

update shopping_cart set price =      (select price products id = shopping_cart.product_id) 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -