Jump to content

Can some one explain this array?


ballhogjoni

Recommended Posts

Ok, this may be complicated, for me it is over my head. How can you tell php to create a xml structure for the following code?

 

<?php
function showCart() {
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[] = '<form action="cart.php?action=update" method="post" id="cart">';
	$output[] = '<table width="500px" style="border:1px solid #EEEEEE;">';
	$output[] = '<tr>';
	$output[] = '<td>';
	$output[] = '<table align="center">';
	$output[] = '<tr>';
		$output[] = '<td align="center" class="style1">Item</td>';
		$output[] = '<td align="center" class="style1">Qty</td>';
		$output[] = '<td align="center" class="style1">Price</td>';
		$output[] = '<td align="center" class="style1">Sub Total</td>';
		$output[] = '</tr>';
	foreach ($contents as $id=>$qty) {
		$sql = 'SELECT * FROM products WHERE id = '.$id;
		$result = $db->query($sql);
		$row = $result->fetch();
		extract($row);
		$output[] = '<tr>';
		$output[] = '<td class="style4" align="center">'.$title.'</td>';
		$output[] = '<td align="center"><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
		$output[] = '<td class="style4" align="center">$'.$price.'</td>';
		$output[] = '<td class="style4" align="center">$'.($price * $qty).'</td>';
		$output[] = '<td align="center"><a href="cart.php?action=delete&id='.$id.'" class="r"><img src="images/delete.jpg" alt="delete the diaper cake product" border="0" width="22" height="25"></a></td>';
		$total += $price * $qty;
		$output[] = '</tr>';
	}
	$output[] = '</table>';
	$output[] = '<table align="center" width="500px">';
	$output[] = '<tr>';
	$output[] = '<td>';
	$output[] = '</td>';
	$output[] = '<td align="right">';
	$output[] = '<button type="submit">Update Qty</button>';
	$output[] = '</td>';
	$output[] = '</tr>';
	$output[] = '<tr>';
	$output[] = '<td>';
	$output[] = '</td>';
	$output[] = '<td align="right" style="font-size:large">';
	$output[] = 'Total:';
	$output[] = '</td>';
	$output[] = '<td style="font-size:medium; font-weight:bold; text-align:center;">$'.$total;
	$output[] = '</td>';
	$output[] = '</tr>';
	$output[] = '</table>';
	$output[] = '</form>';
} else {
	$output[] = '<p class="style4">You shopping cart is empty.</p>';
}
return join('',$output);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.