我正在使用 URL 中的 add 将项目添加到我的 cart.php 中。
case "add":
if (isset($_SESSION['cart'][$comic_id])) {
$_SESSION['cart'][$comic_id]++;
} else {
$_SESSION['cart'][$comic_id] = 1;}
...我的项目呈现在 cart.php 中的 HTML 表格中。然后我只想从 checkout.php 中的数组中重新调用特定变量,以便客户可以确认订单总额以及他们的个人详细信息。
当我使用以下内容时,我似乎只能使用 SESSION 变量来携带最后添加的项目/行:
$_SESSION['totalnameqty']=$name . " " . $qty . " " . $cost;
...然后在 checkout.php 页面上使用回显:
$totnamqty=$_SESSION['totnamqty'];
echo $totnamqty;
...我想将添加到 cart.php 中的 HTML 表中的所有项目 $name、$qty 和 $cost 带到 checkout.php,而不仅仅是 1 个项目/行。不确定如何执行此操作或是否可能。有人可以帮忙吗?
这是我的购物车.php:
if (isset($_SESSION['cart'][$comic_id])){
echo "<table border=\"0\" padding=\"10\" width=\"80%\">";
echo "<td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>";
echo "<td colspan=\"6\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Crystal Fusion: Are you sure you wish to empty your cart?');\">Empty Cart</a></td>";
echo "<tr height=\"20px\">";
echo "<tr height=\"20px\">";
echo "<td align=center>Image</td><td align=center>Title</td><td align=center>Description</td><td colspan=3 align=center>Copies (+/-)</td><td align=center>Price</td>";
echo "<tr height=\"20px\">";
foreach($_SESSION['cart'] as $comic_id => $qty) {
$sql = sprintf("SELECT title, description, cost, image_thumbnail
FROM comic
WHERE comic_id = %d;",$comic_id);
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {
list($name, $description, $price, $image_thumbnail) = mysql_fetch_row($result);
$cost = $price * $qty;
$total = $total + $cost;
$cost = number_format($cost,2);
$total = number_format($total,2);
$description = substr($description, 0, 250);
echo "<br><tr>";
echo "<td width=\"10px\" align=\"center\"><img height=100 align=center src=\"$image_thumbnail\">";
echo "<td align=\"center\">$name</td>";
echo "<td width=\"40%\" align=\"center\">$description...<a href=comic_dyn.php?comic_id=$comic_id>More Info</td>";
echo "<td width=\"30px\" align=\"center\"><a href=\"$_SERVER[PHP_SELF]?action=add&comic_id=$comic_id\">+<br></a><td align=\"center\">$qty <td width=\"20px\" align=\"center\"><a href=\"$_SERVER[PHP_SELF]?action=remove&comic_id=$comic_id\">-</a></td>";
echo "<td align=\"right\">$$cost</td>";
echo "</tr>";
}
}
echo "<br><tr><tr height=100px>";
echo "<td><td><td colspan=\"4\" align=\"right\">Total:</td>";
echo "<td width=\"60px\" align=\"right\">$$total</td>";
echo "<tr><td colspan=\"7\" align=\"right\"><a href=\"checkout_html.php\">Proceed to Checkout</a>";
echo "<tr height=\"50px\">";
echo "</table>";
}else{
echo "Your cart is currently empty.";
echo "<br><br><td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>";
}
//session variables (to be carried to checkout.php
$_SESSION['cost']=$cost;
$_SESSION['name']=$name;
$_SESSION['qty']=$qty;
$_SESSION['totnamqty']=$name . " " . $qty . " " . $cost;