Jump to content

Outputs not working


ballouta

Recommended Posts

Hi,

I have this write ShowCart() function

<?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>';
	foreach ($contents as $id=>$qty) {
		$sql = 'SELECT * FROM `acc` WHERE `article` = '.$id;
		$result = $db->query($sql);
		$row = $result->fetch();
		extract($row);

		$output[] = '<tr>';
		$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
		$output[] = '<td>'.$row[subcategory].' by '.$row[descr].'</td>';
		$output[] = '<td>€'.$price.'</td>';
		$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
		$output[] = '<td>€'.($row[price] * $qty).'</td>';
		$total += $row[price] * $qty;
		$output[] = '</tr>';
	}
	$output[] = '</table>';
	$output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>';
	$output[] = '<div><button type="submit">Update cart</button></div>';
	$output[] = '</form>';
} else {
	$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}
?>

 

Note that I replaced $subcategory with $row[subcategory] AND $price with $row[price].

with and without $row the output doesn't appear at all and prices are zeros!

 

What is the problem?

How Do i Make sure that the connection to the DB is working and is really getthing teh result?

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/147284-outputs-not-working/
Share on other sites

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.