ループで実行されるこのショッピング カート スクリプトがありますが、電子メールで送信しようとすると、9 個以上のアイテムを電子メールで送信することしかできません。電子メールは空白になります。'SELECT * FROM books WHERE id = '.$id;
ループなしですべてのアイテムを返すクエリに変更する必要があると言われました。これは正しいですか、どうすればよいですか? もしそうなら、誰かが私がそれをどのように行うかの例を教えてもらえますか?
<?php
function showCarts() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<table style="border-width:1px; bordercolor="#0099FF"">';
$output[] = '<tr>';
$output[] = '<thead bgcolor="#0099FF">';
$output[] = '<th>Item</th>';
$output[] = '<th>Price</th>';
$output[] = '<th>Quantity</th>';
$output[] = '<th>Total</th>';
$output[] = '</thead>';
$output[] = '</tr>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td>'.$title.' by '.$author.'</td>';
$output[] = '<td>$'.$price.'</td>';
$output[] = '<td>'.$qty.'</td>';
$output[] = '<td>$'.($price * $qty).'</td>';
$total += ($price * $qty);
$output[] = '</tr>';
}
$output[] = '</table>';
$tax = (.07);
$taxtotal += round($total * $tax,2);
$amounttotal += ($total + $taxtotal);
$output[] = '<p>Tax: <strong>$'.$taxtotal.'</strong></p>';
$output[] = '<p>Total: <strong>$'.$amounttotal.'</strong></p>';
}
return join('',$output);
}
?>