Ich spiele gerade mit einem PHP Warenkorb und versuche die Bestellung des Kunden per E-Mail an den Verkäufer zu senden.PHP Warenkorb Bestellung, die per E-Mail versandt wird nur das letzte bestellte Produkt und nicht jedes bestellte Produkt
Mein Problem ist, dass, wenn mehrere Artikel bestellt werden, nur der letzte tatsächlich in der E-Mail gesendet wird, aber wenn ich echo, werden alle Elemente angezeigt.
Könnten Sie bitte erklären, warum das passiert?
if(isset($_SESSION["products"])){
$total = 0;
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm){
$product_code = $cart_itm["code"];
$results = $mysqli->query("SELECT product_name,product_desc, price FROM products WHERE product_code='$product_code' LIMIT 1");
$rows = array();
while ($obj = $results->fetch_object()){
$rows[] = $obj;
echo $rows[0]->product_name.' x '.$cart_itm["qty"].' ; '; // here is ok
$prod_name = ($rows[0]->product_name); // here only the last product displays. Why?!
}
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
$cart_items ++;
}
}
$prod_name = str_replace($cyr, $lat, $prod_name);
$random = rand(72891, 92729);
$subject = "New order #$random";
$message = "You have new order from $name $lname with adress $curraddr and order details: $prod_name with a total value of $total dollars.";
$from = "From: [email protected]";
$to = "[email protected]";
mail($to, $subject, $message, $from);
WOW Vielen Dank für den Hinweis, ich wusste nicht, dass es so einfach war. Ich brauchte nur $ prod_name. = $ Obj-> product_name. 'x'. $ cart_itm ["Menge"]. ' ; '; aber ich wusste nicht, dass ich es mit ". =" Danke nochmal machen kann! –