$cartOutput = "";
$cartTotal = "";
$ctr= 0;
$collector = array();
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
}
$pricetotal = $price * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
$product_id_array .= "$item_id-".$each_item['quantity'].",";
$cartOutput .= "<tr>";
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
$cartOutput .= '<td>' . $details . '</td>';
$cartOutput .= '<td>₱' . $price . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post">
<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
<input name="adjustBtn' . $item_id . '" type="submit" value="change" />
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form></td>';
$cartOutput .= '<td>' . $pricetotal . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
$cartOutput .= '</tr>';
//$collector [$ctr][] = $item_id;
//$collector [$ctr][] = $product_name;
//$collector [$ctr][] = $price;
//$collector [$ctr][] = $pricetotal;
//$collector [$ctr][] = $cartTotal;
$ctr++;
//$itemid = $item_id;
// $productname = $product_name;
// $prices = $price ;
// $pricetotals = $pricetotal;
// $total = $cartTotal;
$i++;
// foreach ($collector as $key => $values) {
//echo $values; }
// if ($_POST['checkout']) {
// mysql_query("INSERT INTO transaction (trans_id, transaction_num, item_id, product_name, price, pricetotal, total) VALUES ('','$transnum','$itemid','$productname','$prices','$pricetotals','$total')");
//}
}
}
echo var_export($collector);
jcyarra 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.