Jump to content

Gladiador

New Members
  • Posts

    1
  • Joined

  • Last visited

Gladiador's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. this is a code of a shopping cart i'm trying to make. the cart displays the products with: name, size, price, quantity and total. When checked out it saves on Mysql DB. So it saves like this: user_1 | pants | XL | 10 $ | 1 | 10 $ | user_1 | t-shirt | L | 5 $ | 2 | 10 $ | user_2 | sock s | 8 | 7 $ | 5 | 35 $ | it's creating new row for each product for the same user. But what i need is this: user_1 | pants, t-shirt | XL, L | 10, 5 $ | 1, 2 | 20 $ | user_2 | socks | 8 | 7 $ | 5 | 35 $ | user_3 | t-shirt, hat | M, S | 5, 10 $ | 1, 1 | 15 $ | for the same user he implodes the data in the column of the same row. code: $products_array[$i] = array("user" => $user, "product" => $name_product, "size" => $size, "price" => $price, "quantity" => $each_item['quantity'], "total" => $cartTotal); if (isset($_SESSION["cart_array"]) && count($products_array) > 0 && isset($_POST['addOrder'])) { foreach ($products_array as $product) { $user = $_SESSION["user"]; $name_product = $product['name_product']; $size = $product['size']; $price = $product['price']; $quantity = $product['quantity']; $cartTotal = $product['total']; $result = mysqli_query($dbc,"INSERT INTO shop (user, product, size, price, quantity, total, date) VALUES('$user','$name_product','$size','$price','$quantity','$cartTotal',now())"); header("location: shop_cart.php"); } } So i been googling arround, and found that what i need is a implode function. But my problem is where and how to set it right. I have tried some code already but it doesnt work. I dont want to flood the DB Table with multiple rows of the same purchase. Any other suggestions on what to do to achieve my goal is accepted. Appreciate your help. Thank you.
  2. Hi!! My name is Afzal, i'm from Portugal. I started about 4 months ago learning by myself web programming. Went from HTML > CSS > PHP ...and next i will go to JS. i dont have any friend who programs, so i dont have anyone to talk about coding. Most of the stuff i get from google, but still i have many questions. I hope to learn from you guys, so later i can be able to help others. Thank you. Afzal Aziz
×
×
  • 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.