je viens de programmer un script php qui permet d'augmenté ou diminué une valeur en php, mais le problème viens au niveau d'un deuxième élément quand j'augmente une valeur du premier élément le deuxième élément augmente aussi sa valeur.
Voici le code:
<?php
if(isset($_SESSION["cart_products"])) //check session var
{
$total = 0; //set initial total value
$b = 0; //var for zebra stripe table
foreach ($_SESSION["cart_products"] as $cart_itm)
{
//set variables to use in content below
$product_name = $cart_itm["product_name"];
$product_qty = $cart_itm["product_qty"];
$product_price = $cart_itm["product_price"];
$product_code = $cart_itm["product_code"];
$valide = $cart_itm["valide"];
echo '<tr class="'.$bg_color.'">';
if(!isset($_GET['product_qty'])){
$product_qty = 1;
}
else{
$product_qty=$_GET['product_qty'];
}
if(isset($_GET['action']) && $product_qty >= 1){
if($_GET['action'] == 'incr'){
$product_qty++;
}
elseif($_GET['action'] == 'decr' && $product_qty >= 1){
$product_qty--;
}
}
$subtotal = ($product_price * $product_qty); //calculate Price x Qty
echo '
<td class="cart_quantity">
<div class="cart_quantity_button">';
?>
<a href="http://top.org/check?product_qty=<?php echo $product_qty; ?>&action=decr" class="cart_quantity_up"> - </a>
<?php
echo '<input class="cart_quantity_input" type="text" name="product_qty['.$product_code.']" value="'.$product_qty.'" size="2">';
?>
<a href="http://top.org/check?product_qty=<?php echo $product_qty; ?>&action=incr" class="cart_quantity_up">+</a>
<?
echo '
</div>
</td>';
echo '<td>'.$product_name.'</td>';
echo '<td>'.$product_price.' '.$currency.'</td>';
echo '<td>'.$subtotal.' '.$currency.'</td>';
echo '
<td class="cart_deletes">
<button type="submit" href="" name="remove_code[]" value="'.$product_code.'"><a class="cart_quantity_delete"></a><i class="fa fa-times"></i></button>
</td>';
echo '</tr>';
$total = ($total + $subtotal); //add subtotal to total var
}
$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. ' : '.sprintf("%01.2f", $value).' '.$currency.'<br />';
}
$shipping_cost = ($shipping_cost)?'Frais de port : '.sprintf("%01.2f", $shipping_cost).$currency.'<br />':'';
}
?>