Hi all,
i am working on a shopping system with an array integration but when i want to display the items in my cart,
it displays all items that are the same many times ive tried using an if and else statement but seems to not be working well semi working it just displays 1 of each item but not sure what i am doing wrong,
ive tried to print out the array using this
[PHP
print_r($_session['cart']);
[/PHP]
and this is the result
Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 [21] => 0 [22] => 6 [23] => 6 [24] => 6 [25] => 6 [26] => 6 [27] => 6 [28] => 6 [29] => 6 [30] => 6 [31] => 6 [32] => 6 [33] => 6 [34] => 6 )
Now this is my php code
The abov code is displaying the followingPHP Code:include("dbconnect.php");
$cQuery="SELECT * FROM shop";
$result=mysqli_query($con,$cQuery);;
if(!$result)
{
echo "Error:".mysqli_error($con);
}
else
{
$count=$result->num_rows;
if($count>0)
{
while($data=$result->fetch_assoc())
{
$items[]=$data['name'];
$prices[]=$data['cost'];
$str[]=$data['str'];
}
}
else
{
echo "No Items in ShOP";
}
}
//
$total = 0; // add up the total
// list the quantities in the cart rather than the catalog
?>
<table>
<tr>
<th>Item:</th>
<th>Price:</th>
<th>Quanty:</th>
</tr>
<?
for ($i = 0; $i < count($_SESSION['cart']); $i++)
{
print_r($_SESSION['cart']);
if($e>=2)
{
//
echo '<tr>
<th>'.$items[$_SESSION['cart'][$i]].'</th>
<th>$'.$prices[$_SESSION['cart'][$i]].'</th>';
//echo '<th>'.count($items[$_SESSION['cart'][$i]]).'</th></tr>';
//
}
else if($e<2)
{
echo '<tr>
<th>'.$items[$_SESSION['cart'][$i]].'</th>
<th>$'.$prices[$_SESSION['cart'][$i]].'</th>';
echo '<th>e1</th></tr>';
}
$total += $prices[$_SESSION['cart'][$i]];
}?>
<tr>
<th>Total</th>
<th>$<?php echo number_format($total, 2); ?></th>
</tr>
</table>
<?
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
broken stick $100 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Stead $50,000 e1
Why is it doing that should display this
Stead x 16
Broken Stick x 22
What am i doing wrong??







(actually I didn't have to do something I thought I was going to have to do.)
Bookmarks