Hi there,
I am building a cart system to display Quanties of items each item show if its one or more etc and i am having trouble of doing this i thought i can count each item but not sure how to go about doing it this is what i have atm
session_start();
error_reporting(E_ALL);
$items=array();
$cost=array();
include("dbconnect.php");
$cQuery="SELECT * FROM music WHERE type='0'";
$result=mysqli_query($con,$cQuery);
if(!$result)
{
echo "Error:".mysqli_error($con);
}
else
{
$count=$result->num_rows;
if($count>0)
{
echo "<table border=\\"1\\">
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Buy</th>
</tr>
";
//
//
while($data=$result->fetch_assoc())
{
$items[]=$data['name'];
$cost[]=$data['cost'];
$id[]=$data['mid'];
}
}
else
{
echo "<br/>There is no products in the catalog,Please contact the webmaster of this store";
}
}
?>
<table border="1">
<tr>
<th colspan="2">Cart</th>
</tr>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
<?php
$total = 0; // add up the total
// list the quantities in the cart rather than the catalog
for ($i = 0; $i <=count($_SESSION['cart']); $i++)
{
$qty_sum = 0;
$cartitems = $items[$_SESSION['cart'][$i]];
if($cartitems>=1)
{
$qty=count($cartitems);
echo $qty;
}
echo '<tr><th>'.$items[$_SESSION['cart'][$i]].'</th>';
echo '<th align="right">$'.number_format($cost[$_SESSION['cart'][$i]], 2).'</th></tr>';
$total += $cost[$_SESSION['cart'][$i]];
}
?>
<tr>
<th align="right">Total:</th>
<th align="right">$<?php echo number_format($total, 2); ?></th>
</tr>
</table>
Am i doing somthing wrong here i tried to see if i could do a print_r on the session just it brought up 0 and 1 in each seperate array
What am i doing wrong can anyone help me out here?
Thanks,William