220061
Well-Known Coder
can I calculate the total price depending on the number that the user types into the input?
so for example
idk how to do this? this is my code. I have been looking around on the internet but they only gave me examples of how their shopping cart was looking. I don't want that I want ot be able to understand how to do this with my shopping cart code.
so for example
idk how to do this? this is my code. I have been looking around on the internet but they only gave me examples of how their shopping cart was looking. I don't want that I want ot be able to understand how to do this with my shopping cart code.
PHP:
<?php
include "config.php";
?>
<div class="text-center" style="font-size: 100px;">🛍</div>
<h2 class="text-center">Winkelmandje</h2><br>
<section class="container content-section">
<!-- <h2 class="section-header">CART</h2> -->
<div class="cart-row">
<span class="cart-item cart-header cart-column">ITEM</span>
<span class="cart-price cart-header cart-column">PRICE</span>
<span class="cart-quantity cart-header cart-column">QUANTITY</span>
</div>
<?php
$broodjes = $_GET['broodjes_ID'];
if (isset($_SESSION['basket'])){
if( in_array( $broodjes ,$_SESSION['basket']) )
{
}else{
$_SESSION['basket'][] = $broodjes;
}
}else{
$_SESSION['basket'][]= $broodjes;
}
$sum = 0;
foreach($_SESSION['basket'] as $key => $value){
//echo "Key = $key; value = $value; <br>";
$sql = "SELECT broodjes_ID, broodnaam, prijs, voorraad FROM broodjes WHERE broodjes_ID=$value";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_assoc($result)){
echo '<div class="cart-items">';
echo '<div class="cart-row">';
echo '<div class="cart-item cart-column">';
echo $row['broodnaam'];
echo '</div>';
echo '<div class="cart-item cart-column">';
echo $row['prijs'];
echo "</div>";
echo '<div class="col-xs-4">';
echo '<input type="text" class="form-control input-sm" value="1">';
echo '</div>';
echo '</div>';
echo '</div>';
//$sum = $row['prijs'] *
$sum += $row['prijs'];
}
}
?> <br />
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € <?php echo $sum;?></span>
</div>
<br/>
<button type="button" class="btn btn-danger"><a href="emptyarray.php"> Bestellen</a></button>
<br>
<br />
</section>
</body>