I'm not seeing what goes wrong here? I want to allow my users to up the quantity from an item in their shopping cart. when they press enter I want the quantity to change from 1 to the number the use rput in and I want that it calculates everything correctly. but right now it only wants to update the last item that the user changed the quantity from. how do I fix this? I thought of using a $_SESSION but that doesn't make any difference. this is part of the code
<body>
<!--navbar-->
<a class="back" href="index.php"> <i class="bi bi-arrow-left-circle-fill bi-5x"></i></a>
<?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-item cart-header cart-column">PRICE</span>
<span class="cart-item cart-header cart-column">QUANTITY</span>
<span class="cart-item cart-header cart-column">berekening</span>
<!-- <span class="cart-item cart-header cart-column">Verwijderen</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;
}
$sumtotal = 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=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $value);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
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>';
//quantity
echo '<div class="cart-item cart-column">';
echo '<form method="POST" action"">';
echo '<div class="col-xs-4">';
echo '<input type="hidden" name="broodnaam" id="broodnaam" value="' . $row['broodnaam'] . '">';
echo '<input type="number" name="quantity" id="quantity" class="form-control input-sm" placeholder="1" min="1" max="100" value="1">';
echo '</div>';
echo '</form>';
echo '</div>';
//session for quantity???'
$_SESSION['quantity'] = $_POST['quantity'];
$quantity = 1;
if (isset($_POST['quantity']) && !empty($_POST['quantity'])){
$_SESSION['quantity'] = $_POST['quantity'];
if (isset($_POST['broodnaam']) && !empty($_POST['broodnaam'])){
if ($_POST['broodnaam'] == $row['broodnaam']){
$quantity = $_POST['quantity'];
}
}
}
echo '<div class="cart-item cart-column">';
$rowtotaal = $row['prijs'] * $quantity;
$sumtotal += $rowtotaal;
echo $rowtotaal;
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?> <br />
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € <?php echo $sumtotal;?></span>
</div>
<br/>
and this is what it does
now situation:
how do I store the information in a session??
Related
I have to make a website that will rank project si I've decided to use star ranking system. All works well until I add a new project.
The problem is when I rate the second project my code think it is the first one that he need to rate.
When I get all the websites with PHP, the numbers are good (input type text to see the number)
What I see on the index
But when I click on the star below the number 51, the output of the echo is 53.
Gets all the websites :
try
{
$stmt = $db->query('SELECT sites.id, sites.programme, ROUND(AVG(rating.rating_number), 2) AS rating_number, sites.annee, sites.titre, sites.equipe, sites.image_preview, sites.lien, sites.campus, sites.date_send FROM sites
INNER JOIN rating
WHERE sites.id = rating.post_id
GROUP BY sites.id
ORDER BY ROUND(AVG(rating.rating_number), 2) DESC LIMIT 30');
while($row = $stmt->fetch())
{
$date_envoie_site = strtotime($row['date_send']);
$date_maintenant = strtotime("now");
$calcul = $date_maintenant - $date_envoie_site;
echo '<div class="col custom-card">';
echo '<div class="card shadow-6-strong h-100">';
echo '<img src="img/sites/' .$row["image_preview"]. '" class="card-img-top" height="320" alt=""/>';
echo '<div class="card-body">';
if ($calcul < 86400)
{
echo '<h4 class="card-title text-center"><span class="badge bg-primary">NOUVEAU</span> ' .$row["titre"]. '</h4> ';
}
else
{
echo '<h4 class="card-title text-center">' .$row["titre"]. '</h4> ';
}
echo '<hr>';
echo '<h6 class="card-title"><i class="fa-solid fa-city"></i> ' .$row["campus"]. '</h6>';
echo '<h6 class="card-title"><i class="fa-solid fa-book"></i> ' .$row["programme"]. '</h6>';
echo '<h6 class="card-title"><i class="fa-solid fa-calendar-alt"></i> ' .$row["annee"]. '</h6>';
echo '<h6 class="card-title"><i class="fa-solid fa-users"></i> ' .$row["equipe"]. '</h6>';
echo '<form method="POST">';
echo '<input type="text" name="post_id" value="'.$row['id'].'">';
echo '<div class="rating-wrap">
<div class="center">
<fieldset class="rating">
<input type="submit" id="star5" name="star5" value="5"/><label for="star5" class="full" title="Awesome"></label>
</fieldset>
</form>
</div>
<h4 id="rating-value"></h4>
</div>';
echo '<h6 class="card-title"><i class="fa-solid fa-star"></i> ' .$row["rating_number"]. '/5</h6>';
echo '</div>';
echo '<div class="card-footer text-center">';
echo '<button type="button" class="btn btn-primary btn-lg btn-block button-custom"><i class="fa-solid fa-eye"></i> Voir le site</button>';
echo '</div>';
echo '<div class="card-footer text-center">';
echo '<div class="d-flex justify-content-evenly pb-2">';
echo '<i class="fa-brands fa-facebook fa-3x"></i>';
echo '<i class="fa-brands fa-twitter fa-3x"></i>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
catch(PDOException $e) { echo $e->getMessage();}
When I click on the star
if (isset($_POST['star5']))
{
$id = $_POST['post_id'];
echo $_POST['post_id'];
/*
$sql = "INSERT INTO rating(post_id, rating_number) VALUES (:post_id, :rating_number) WHERE post_id = '$id'";
$stmt = $db->prepare($sql);
$stmt->bindParam(':post_id', $_POST['id'], PDO::PARAM_STR);
$stmt->bindParam(':rating_number', $_POST['star5'], PDO::PARAM_STR);
$stmt->execute();
$stmt->closeCursor();
*/
}
I am having a difficult time figuring out how to break a section out of a an else-statement that is nested within a foreach loop.
The section I want to break out of the foreach loop is :
echo '
<div class="moreEventsContainer">
<div id="moreEventsWrap" class="total-center">
<span class="moreEventsLink">SEE ALL EVENTS</span>
<div class="rightArrow"></div>
</div>
</div>'
;
The thing is that it is part of the else statement, but leaving it in the loop just makes it duplicate itself over and over when I just want it to appear once.
Does anyone see how I can do this?
I tried doing the alternative endforeach nested before the end of the else statement, but it just broke the code.
Any ideas?
foreach ($event_rows as $event_row) {
$event_name = $event_row['event_name'];
$display_date = $event_row['display_date'];
$event_description = $event_row['small_desc'];
$end_date = new DateTime($event_row['end_date']);
$date = new DateTime('now');
if ($date >= $end_date) {
//$noEvents = 'No events are scheduled yet.';
$noEvents = '
<div id="noEvents">
</div>
';
} else {
echo '<div class="eventBlock">';
echo '<div class="total-center eventBlockWrap">';
echo '<span class="displayDate">'. $display_date .'</span>';
echo '<span class="eventName">'. $event_name .'</span>';
echo '<p class="dGsmall margNone">'. $event_description .'</p>';
echo '</div>';
echo '</div>';
echo '<div class="moreEventsContainer">
<div id="moreEventsWrap" class="total-center">
<span class="moreEventsLink">SEE ALL EVENTS</span>
<div class="rightArrow"></div>
</div>
</div>'
;
}
}
if ($noEvents != NULL) {
echo $noEvents;
} else {
}
Update:
foreach ($event_rows as $event_row) {
$event_name = $event_row['event_name'];
$display_date = $event_row['display_date'];
$event_description = $event_row['small_desc'];
$end_date = new DateTime($event_row['end_date']);
$date = new DateTime('now');
if ($date >= $end_date) {
//$noEvents = 'No events are scheduled yet.';
$noEvents = '
<div id="noEvents">
</div>
';
} else {
echo '<div class="eventBlock">';
echo '<div class="total-center eventBlockWrap">';
echo '<span class="displayDate">'. $display_date .'</span>';
echo '<span class="eventName">'. $event_name .'</span>';
echo '<p class="dGsmall margNone">'. $event_description .'</p>';
echo '</div>';
echo '</div>';
break;
echo '<div class="moreEventsContainer">
<div id="moreEventsWrap" class="total-center">
<span class="moreEventsLink">SEE ALL EVENTS</span>
<div class="rightArrow"></div>
</div>
</div>'
;
}
}
According to your update,
I suppose you want this code
echo '<div class="moreEventsContainer">
<div id="moreEventsWrap" class="total-center">
<span class="moreEventsLink">SEE ALL EVENTS</span>
<div class="rightArrow"></div>
</div>
</div>';
to execute once, after all of your records are shown.
So, I suggest using this instead of the break statement
if($i==sizeof($event_rows)){
echo '<div class="moreEventsContainer">
<div id="moreEventsWrap" class="total-center">
<span class="moreEventsLink">SEE ALL EVENTS</span>
<div class="rightArrow"></div>
</div>
</div>';
}
Where $i is initialized to 1 and incremented each time the loop executes.
I have a form with a submit button.
<input type="submit" name="submitOrder" id="submitOrder" value="Purchase" class="btn btn-warning">
Below this I have a couple lines of code:
<?php
if (isset($_POST['submitOrder'])) {
header ("location:payment.php?discount=". $discountCode ."");
}
?>
Why does that button when clicked, do nothing but reload the page? I want it to redirect the user to payment.php?
Entire form with the submit button...
<form method="post" action="cart_update.php">
<div class="row" style="padding-bottom: 10px;">
<div class="col-md-2">
<strong>Quantity</strong>
</div>
<div class="col-md-3">
<strong>Name</strong>
</div>
<div class="col-md-2">
<strong>Price</strong>
</div>
<div class="col-md-2">
<strong>Total</strong>
</div>
<div class="col-md-3">
<strong>Remove</strong>
</div>
</div>
<?php
if(isset($_SESSION["cart_products"])) { // Check session var
$total = 0; // Set initial total value
foreach ($_SESSION["cart_products"] as $cart_itm) {
// Set variables to use in content below
$ProductName = $cart_itm["ProductName"];
$product_qty = $cart_itm["product_qty"];
$Price = $cart_itm["Price"];
$ProductCode = $cart_itm["ProductCode"];
$subtotal = ($Price * $product_qty); // Calculate Price x Qty
echo '<div class="row" style="padding: 10px 0;">';
echo '<div class="col-md-2">Qty: <input type="text" size="2" maxlength="4" name="product_qty['. $ProductCode .']" value="'. $product_qty .'" /></div>';
echo '<div class="col-md-3">Product Name: '. $ProductName .'</div>';
echo '<div class="col-md-2">Price: '. $currency . $Price .'</div>';
echo '<div class="col-md-2">Total: £';
echo money_format('%i', $subtotal);
echo '</div>';
echo '<div class="col-md-3"><input type="checkbox" name="remove_code[]" value="'. $ProductCode .'" /></div>';
echo '</div>';
echo '<hr>';
$total = ($total + $subtotal); // Add subtotal to total var
$grand_total = $Price * $product_qty;
}
$grand_total = $total + $shipping_cost; // Grand total including shipping cost
foreach($taxes as $key => $value) { // List and calculate all taxes in array
$tax_amount = round($total * ($value / 100));
$tax_item[$key] = $tax_amount;
$grand_total = $grand_total + $tax_amount; // Add tax val to grand total
}
$list_tax = '';
foreach($tax_item as $key => $value) { // List all taxes
$list_tax .= $key. ' : '. $currency . sprintf("%01.2f", $value).'<br />';
}
$shipping_cost = ($shipping_cost) ? 'Shipping Cost: ' . $currency . sprintf("%01.2f", $shipping_cost).'<br />':'';
}
?>
<br />
<div class="row">
<span style="float: right; text-align: right; width: 100%;">Amount Payable: <strong>£<?php echo sprintf("%01.2f", $_SESSION['grand_total'] = $grand_total); ?><br />Price inc. VAT and Postage + Packaging</strong><br />Discount Code: <input type="text" name="discountCode" id="discountCode" value="TEST" /></span>
<br />
<br />
Continue Shopping
<button type="submit" class="btn btn-warning">Update</button>
<!-- Purchase -->
<input type="submit" name="submitOrder" id="submitOrder" value="Purchase" class="btn btn-warning">
<?php
if (isset($_POST['submitOrder'])) {
header ("location:payment.php?discount=". $discountCode ."");
}
$_SESSION['ProductName'] = $ProductName;
$_SESSION['product_qty'] = $product_qty;
$_SESSION['grand_total'] = $grand_total;
?>
</div>
<input type="hidden" name="return_url" value="<?php $current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); echo $current_url; ?>" />
</form>
The problem is, there is output, before you send the redirect headers, because your condition is in the html section.
You should place the code with the redirect before any output is sent to the client.
An other option would be to turn on output buffering, but this must also be done, before something is sent to the client.
ensure the very first item returned is the header with no whitespace or anything before it ie echos or text,
check the log files for headers already sent errors
make sure the button is inside the form
I have three different div's that contain the checkout information.
Shipping info
Billing Info
Order confirmation
The shipping information and billing information is obtained by the customer entering that information in manually, but the order confirmation, that contains what they are ordering, the quantity, and pertinent information to that order resides there. That information is obtained from a foreach loop I have in place that displays the information based on the product's ID.
I am trying to figure out how I am going to INSERT the string that displays from my foreach loop into my database. I have an order report page that I want to display what was ordered.
For the shipping information, I validate it and then send my query in with that information. Like this...
<?php
if(Input::exists()) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'fullname' => array(
'required' => true,
'min' => 2,
'max' => 50
)
if($validation->passed()) {
if(isset($_POST['create'])){
$fullname = trim( $_POST['customer_name'] );
?>
<div class="field">
<label class="paddingleft" for="fullname">Full Name</label>
<div class="center"><input type="text" class="biginputbarinline" name="fullname" value="<?php echo escape(Input::get('firstname')); ?>" required></div>
</div>
The part that I am really confused with is how to INSERT the actual string this foreach loop displays. If the result of my foreach loop was:
2 balls
4 shoes.
I want that information to send in with my query.
This is how I have the Order confirmation section as of now..
<div class="checkoutconfirmationcontainer">
<?php foreach($_SESSION['shopping_cart'] as $id => $product) {
$product_id = $product['product_id'];
?>
<span class="tealmedium"><?php echo $product['quantity'] . " - " . $products[$product_id]['name'] . $message; ?></span><br><br><br>
<div class="floatleft"><div class="smallerimgcontainer">
<?php
$result = mysqli_query($con,"SELECT * FROM products");
if($row = mysqli_fetch_array($result)) {
$products[$row['product_id']] = $row;
if($row['image'] == ""){
echo "<img class='sizedimg' src='/productpics/coming_soon.png' alt='Coming Soon'>";
} else {
echo "<img class='sizedimg' src='/productpics/".$row['img']."' alt='Product Picture'>";
}
echo "<br><br><br><br>";
}
?>
</div></div>
<div class="checkoutitemsummary">
<?php echo "<a href='./viewProduct.php?view_product=$id'>" . $product['name'];?><?php echo $products[$product_id]['name']; ?> </a>
<p><span class="redprice"><?php echo '$' . $products[$product_id]['price'] . "<br />"; }?></span></p>
</div>
How can I get the results of my foreach loop to be inserted into my database with my query?
Shopping Cart
<tr>
<th class="cartth">Name</th>
<th class="cartth">Price</th>
<th class="cartth">Category</th>
<th class="cartth">Quantity</th>
</tr>
<?php
$base_price = 0;
foreach($_SESSION['shopping_cart'] as $id => $product) {
$product_id = $product['product_id'];
$base_price += $products[$product_id]['price'] * $product['quantity'];
$shipping_price += $products[$product_id]['shippingprice'] * $product['quantity'];
?>
<tr>
<td class="carttd"><?php echo "<a href='./viewProduct.php?view_product=$id'>" . $product['name'];?><?php echo $products[$product_id]['name']; ?> </a>
</td>
<td class="carttd"><?php echo '$' . $products[$product_id]['price']; ?></td>
<td class="carttd"><?php echo $products[$product_id]['category']; ?></td>
<td class="carttd">
<?php echo "<input type='text' name='quantity[$product_id]' value='" . $product['quantity'] . "' />"; ?> </td>
</tr>
<?php
}
Javascript/Jquery that produces my div transition:
$('.checkoutmenu>li').on('click',function(e){
$('.checkoutprocess>.'+ e.target.classList[0]).show().siblings().hide();
});
<script>
$('.paymentinfocontainer').hide();
$('.confirmationinfocontainer').hide();
</script>
<script>
$('#button2').click(function () {
$(".checkoutprocess > div").hide();
$('.paymentinfocontainer').show("slow");
});
</script>
<script>
$('#button3 ').click(function () {
$(".checkoutprocess > div").hide();
$('.confirmationinfocontainer').show("slow");
});
</script>
<script>
/*
$('#button1').click(function () {
$(".checkoutprocess > div").hide();
$('.shippinginfocontainer').show("slow");
});
</script>
<script>
$('#button2 ').click(function () {
$(".checkoutprocess > div").hide();
$('.paymentinfocontainer').show("slow");
});
</script>
<script>
$('#button3 ').click(function () {
$(".checkoutprocess > div").hide();
$('.confirmationinfocontainer').show("slow");
});
*/
</script>
Ok, when I clicked on "3. Order Confirmation", I got the following HTML:
<div class="confirmationinfocontainer" style="display: block;">
<span class="summarytitle"><p>Order Confirmation</p></span>
<br>
<div class="floatrightinline">
<div class="confirmshippinginfo">
<p>Shipping to:</p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
</div>
<div class="checkoutconfirmationcontainer">
<div name="product_id"></div>
<span class="tealmedium">1 - Lakers Hat</span>
<br>
<br>
<br>
<div class="floatleft">
<div class="smallerimgcontainer">
<img alt="Coming Soon" src="/productpics/coming_soon.png" class="sizedimg">
<br>
<br>
<br>
<br>
</div>
</div>
<div class="checkoutitemsummary">
Lakers Hat
<p><span class="redprice">$25<br></span></p>
</div>
<input type="hidden" value="405bb6b2b562b4f00dac620d3f68620f" name="token">
<input type="submit" value="Place Your Order" class="widebutton">
<br>
</div>
</div>
So I see you're already making use of a hidden field. So when a users clicks the "Place Your Order" button, you want the details to be passed along. You can simply add these details back to the form via a hidden field. Like so:
<div class="checkoutconfirmationcontainer">
<?php
foreach($_SESSION['shopping_cart'] as $id => $product) {
$product_id = $product['product_id'];
?>
<input type="hidden" name="product_quantity[<?php echo $id; ?>]" value="<?php echo $product['quantity']; ?>" />
<span class="tealmedium"><?php echo $product['quantity'] . " - " . $products[$product_id]['name'] . $message; ?></span><br><br><br>
<div class="floatleft"><div class="smallerimgcontainer">
<?php
$result = mysqli_query($con,"SELECT * FROM products");
if($row = mysqli_fetch_array($result)) {
$products[$row['product_id']] = $row;
if($row['image'] == ""){
echo "<img class='sizedimg' src='/productpics/coming_soon.png' alt='Coming Soon'>";
} else {
echo "<img class='sizedimg' src='/productpics/".$row['img']."' alt='Product Picture'>";
}
echo "<br><br><br><br>";
}
?>
</div></div>
<div class="checkoutitemsummary">
<?php echo "<a href='./viewProduct.php?view_product=$id'>{$product['name']} {$products[$product_id]['name']}</a>"; ?>
<p><span class="redprice"><?php echo '${$products[$product_id]['price']}<br />"; }?></span></p>
</div>
<input type="hidden" name="token" value="405bb6b2b562b4f00dac620d3f68620f">
<input class="widebutton" type="submit" value="Place Your Order">
<br />
</div>
Looking over this, I see no <form> for this. So I suspect JQuery is handling this somewhere else. So my fix may not really get read if your JQuery or app does not now what to look for, or does not hook onto that hidden field. If this is a framework that you're using or Catalog that you're modifying, check their support. I would say you have a lot more work ahead of you.
I would greatly enjoy knowing how to separate the results of my query based on the "season" using PHP only. The products should be placed in separate divs according to what season they are for. I would also like to do this in the most efficient way possible. I have thought about his for some time and have failed both in a solution and in finding someone else's similar results on the internet. Please ignore the jquery, it is a leftover for something I may or may not use.
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<link rel="stylesheet" type="text/css" href="style/main.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0
/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.simplyscroll.min.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
$("#scroller").simplyScroll();
});
})(jQuery);
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Shop</li>
<li>Contact</li>
</ul>
</div>
</div>
<div id="content">
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//$results = $db->query('SELECT id, name, thumb, description, price, season FROM products
BY season ASC');
foreach($db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC') as $results){
if ($results) {
//output results from database
$last_season = 1;
echo '<div class="products">';
while($obj = $results->fetch_object())
{
if ($last_season != $obj->season){
echo '</div><div class="products">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button
class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>';
}
}
?>
<div id="shopping-cart">
<h2>Your Shopping Cart</h2>
<?php
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["products"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&
return_url='.$current_url.'">×</a></span>';
echo '<h3>'.$cart_itm["name"].'</h3>';
echo '<div class="p-code">P code : '.$cart_itm["code"].'</div>';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div class="p-price">Price :'.$currency.$cart_itm["price"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt"><strong>Total : '.$currency.$total.'</strong> Check-out!</span>';
echo '<span class="empty-cart"><a href="cart_update.php?emptycart=1&
return_url='.$current_url.'">Empty Cart</a></span>';
}else{
echo 'Your Cart is empty';
}
?>
</div>
</div>
<div id="footer">Footer goes here.</div>
</div>
</body>
</html>
I am getting an error on line 44, which is the start of the "foreach" statement. I am again at a loss. Thank you a ton for your help so far. If I can get this working, with help of course, I will be extremely excited and in your debt.
Here's a loop that will create a new div each time the season changes in a new row. You will need to change the query to order the results by season, e.g.
ORDER BY season ASC
Here's the loop:
if ($results) {
//output results from database
$last_season = 1; //initial value
echo '<div class="season">'; //opens first season div
while($obj = $results->fetch_object()){
if ($last_season != $obj->season){
echo '</div><div class="season">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>'; //closes final season div
}
Regarding the line 44 error in the foreach, I believe what you want there instead of a foreach is simply:
$results = $db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC'); //remember to remove the closing bracket of the foreach