0
PHPショッピングカートで遊んでおり、顧客の注文をメールで売り手に送ろうとしています。PHPショッピングカート注文書には、最後に注文した商品のみが表示され、注文商品のすべてが表示されるわけではありません。
私の問題は、複数の商品が注文されている場合、最後の商品のみがメールで実際に送信されますが、エコーするとすべての商品が表示されるということです。
なぜこれが起こっているのか説明してください。
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はヒントのためにとても感謝しています。 $ prod_name。= $ obj-> product_nameが必要でした。 'x'。$ cart_itm ["qty"]。 ' ; ';しかし、私はそれをすることができるかどうかわからなかった "。="ありがとう! –