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);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.