I manage to erase data but only when there are 2 things in the loop. When there are more than 2 it only deletes 2 in 2 and I do not know why.
<?php
session_start();
if(isset($_GET['p'])){
$_SESSION['producto'][$_SESSION['contador']] = $_GET['p'];
$_SESSION['contador']++;
}
if (isset($_GET['c'])){
$_SESSION['cantidad'][$_SESSION['contador']] = $_GET['c'];
}
include '../conexion/server.php';
$suma = 0;
for ($i=0; $i < $_SESSION['contador']; ++$i){
//echo "producto:".$_SESSION['producto'][$i]."-".$_GET['c'][$i]."<br>";
$query = mysqli_query($conect,'SELECT * FROM Productos WHERE
id='.$_SESSION['producto'][$i].'');
while ($fila = mysqli_fetch_array($query)) {
$cab = $_SESSION['cantidad'][$i+1];
$total = $fila['Precio']*$cab;
echo '<tr>';
echo '<td>'.$fila['Nombre'].'</td>';
echo'<td></td>';
echo '<center><td>';
echo '<center><input type=number name=ja class="las ma"
value='.$cab.'></center>';
echo '</td></center>';
echo '<td>$'.$fila['Precio'].'</td>';
echo '<td>'.$i.'</td>';
echo '<td>$'.number_format($total,2).'</td>';
echo '<td>';
echo '<input type=hidden value='.$_SESSION['contador'].'
class=jk>';
echo '<a href=functions/checkout.php?a='.$i.'
class=borrar>Borrar</a>';
echo '</td>';
echo '</tr>';
$suma += $total;
}
if(isset($_GET['a'])){
unset($_SESSION['producto'][$_GET['a']]);
$_SESSION["producto"] =
array_values($_SESSION["producto"]);
$_SESSION['contador'] -=1;
}
}
echo '<tr><th colspan="5">Total</th><th
colspan="2">$'.number_format($suma,2).'</th></tr>';
mysqli_close($conect);
?>