How can i get the updated cart session array and display it in another php file AJAX

后端 未结 1 1411
灰色年华
灰色年华 2020-12-22 05:55

AJAX

$(document).ready(function(){
//remove product from cart
                $(\".delete-product-cart\").click(function(e){

             var id = $(         


        
1条回答
  •  旧时难觅i
    2020-12-22 06:43

    I think this will help you. I used as manny of your own code. There are many points of improvements but i guess this is a learning project of yours

     0) {
    
      // get the product ids
      // Wy do this? your session is already an array with the ids
      $ids = array();
      // And here you add the key of the array to ids and not the product_id so you will get the wrong products
      foreach ($_SESSION['cart'] as $id => $value) {
        array_push($ids, $id);
      }
    
      $stmt = $product->readByIds($_SESSION['cart']); // Instead of $ids you can add the session
    
      // this works, but add your fetch in your readByIds method to keep your code cleaner and return the array with products
      while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        ?>
        

    0 讨论(0)
提交回复
热议问题