我想在我的变量会话篮中得到一笔钱(它是一个多数组),我想总结代表产品成本的元素。
Page where I add elements into the basket
<?php
session_start();
include('link.php');
if(!isset($_SESSION['basket'])){
$_SESSION['basket']=[];
}
// $id_permit=$_POST['id_fp'];
// $chosen_date=$_POST['date_permit'];
$_SESSION['little_basket']= array (
'itemIdPermit'=> "'".$_POST["id_fp"]."'",
'itemChosenDate'=> "'".$_POST["date_permit"]."'",
'itemFinalPrice'=> "'".$_POST["final_price"]."'",
'itemFinalPriceNotDiscount'=>"'".$_POST["price_not_discount"]."'"
);
// $_SESSION['basket'][] = $_SESSION['little_basket'];
array_push($_SESSION['basket'], $_SESSION['little_basket']);
print_r($_SESSION['basket']);
// $_SESSION['basket']=[];
// echo $_SESSION['basket'];
// header('location:index.php?area=fishing_permit');
?>
Page where I show the contents of the basket
<?php
// session_start();
// include('link.php');
// include('add_basket.php');
// $ids = '';
/* foreach($_SESSION['basket'] as $id){
$ids = $ids . $id . ",";
};*/
$lista_de_items_no_carrinho = $_SESSION['basket'];
?>
<ul id="list_product">
<?php
$basketLength=count($lista_de_items_no_carrinho);
for($i=0;$i< $basketLength;$i++){
$sqlListChosenPermits = "select * from type_of_permits
where id_type_of_permit =".$lista_de_items_no_carrinho[$i]['itemIdPermit'];
$outcomeListChosenPermits = $link->query($sqlListChosenPermits);
$line = mysqli_fetch_assoc($outcomeListChosenPermits);
?>
<li>
<div class="box_info"><h4><?php echo utf8_encode($line['type']); ?></h4><br>Validity: <?php echo utf8_encode($line['validity']);?> - Price: €<?php echo utf8_encode($line['price_eur']); ?> </div>
<div class="map">Map info</div>
<div class="rules">Rules</div>
<div class="permit_facsimile"><a href="<?php echo $line['map']; ?>">Permit facsimile</a></div>
<div class="chosen_date"><?php echo trim ($lista_de_items_no_carrinho[$i]['itemChosenDate'], "'") ;?></div>
<div class="price">Euro <?php
$var= trim ($lista_de_items_no_carrinho[$i]['itemFinalPrice'],"'");
if (!empty($var) ){
echo ($var);
} else {
echo trim($lista_de_items_no_carrinho[$i]['itemFinalPriceNotDiscount'],"'");
} ?></div>
<div class="add_basket"><a href="remove_from_basket.php?id=<?php echo $lista_de_items_no_carrinho[$i]['itemIdPermit']?>"><i class="fa fa-shopping-cart"></i>Remove from the Basket</a></div>
<input type="hidden" name="last_price" id="last_price" value="<?php
if (!empty($lista_de_items_no_carrinho[$i]['itemFinalPrice'])) {
echo trim ($lista_de_items_no_carrinho[$i]['itemFinalPrice'],"'");
} else {
echo trim($lista_de_items_no_carrinho[$i]['itemFinalPriceNotDiscount'],"'");
} ?>">
</li>
<?php
}
?>
</ul>
<p>Total price:<span class="total_price"><?php
$lista_de_items_no_carrinho = $_SESSION['basket'];
$listaPrice=$lista_de_items_no_carrinho[$i]['itemFinalPriceNotDiscount'];
$basketLength=count($listaPrice);
$sum=0;
for($k= 0; $k < $basketLength; $k++){
$sum += ($basketLength[$k]);
echo ($sum);
}?>
</span></p>
<div class="buying"><button type="submit"><i class="fa fa-shopping-cart"></i>Conclude the purchase</button></div>
</div>
我想总算'ItemFinalPrice'和'ItemFinalPriceNotDiscount'的数字值。
提前致谢。
Fanjo