简体   繁体   中英

How to add total price in a cart php

hello i am currently doing a project for an assignment to create a website that sells games, so far i have got everything working perfectly up to the point of adding up the totals of the shopping cart. Below is the PHP part of the cart file that displays a game image and game price everytime it gets put into the cart.

The only value that i am getting is 0.

At the top of this file i have this php file with the query

<?php
require "dbconnect.php";
session_start();
$memberID = $_SESSION['id']; 


$query = "SELECT rectable.gameID, rectable.gameIMG, rectable.gamePrice, rectable.gameName, basket.quantity FROM rectable INNER JOIN basket 
ON rectable.gameID=basket.gameID";

$results = $connect->query($query);
$numrow = $results->num_rows;
?>

Im not sure why this code isnt working:

$i = 0;
    while($count < $numrow){
    $i = $gamePrice*$quantity ;
    }
    echo $i;

Cart.php

<?php
$count = 0;
while ($count < $numrow)
{
$row = $results -> fetch_assoc();
extract($row);
echo"<div>";
echo"<div class='recommended_games'>";
echo "<img src='images/".$gameIMG."' />";
echo "</div>";


echo '<div class="price_tag">';
echo '<div class="price_tag" name="price" method="POST">£'.$gamePrice. '</div>';
echo'</div>';

echo '<div id="update_form"><form action="updatebasket.php" method="POST" name="updateform">';
echo '<select name="quantity" id="quantity" />';
echo      '<option value="1">1</option>';
echo      '<option value="2">2</option>';
echo      '<option value="3">3</option>';
echo      '<option value="4">4</option>';
echo      '<option value="5">5</option>';
echo      '</select>';
echo '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
echo '<input type="submit" value="update" />';
echo '</form>';
echo '<div class="quantity_update">';
echo '<form action="remove_item.php" method="POST">';
echo     '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
echo     '<input type="submit" value="Remove Item"  />';
echo '</form>';
echo '</div>';
echo '</div>';             



echo"<img class='box1' src='Images/Grey-Banners.png' />";
echo"</div>";

$count = $count + 1;   

}     
echo '<div id="delete_all">';
echo '<form action="delete_cart.php" method="POST">';
echo '<input id="hide_button" type="submit" value="Clear All"  />';
echo '</form>';
echo '</div>';

echo '<div id="totalprice">';
echo '<form action="order_items.php" method="POST">';
echo '<input type="submit" value="Confirm Items"  />';
echo '</form>';
echo '</div>';
echo '<div id=totalprice2>' ;
$i = 0;
while($count < $numrow){
$i = $gamePrice*$quantity ;
}
echo $i; 
echo '</div>';
?>

You are not looping through here:

$i = 0;
    while($count < $numrow){
    $i = $gamePrice*$quantity ;
    }
    echo $i;
//add this 
$i++

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM