send a value per url and let it travel in a loop for PHP

0
  echo '<p class="price">$'.$precio.'</p>';
  echo '<p class="buttons">';
  echo '<a href="detail.html" class="btn btn-default">Ver 
          Detalle</a>';
   // input donde ingreso cantidad
  echo '<input type="number" name="ja" value="0" id="jaa" class="la 
   ma">';   
  //boton donde mando el id para posterior consulta                                     
  echo '<button value="'.$id.'" class="boton_compra">Añadir 
         Carrito</button>';

function js with which I send the id and quantity by url

  function anade(){
  var fila = $(this).parents("p");
   if(fila.find(".ma").val() >0){
   $("#carrito").load("functions/poncarrito.php?p="+$(this).val());
   $("#carrito").load("functions/poncarrito.php?
   c="+fila.find(".ma").val());

in the poncarrito php I put this

<?php
session_start();
if(isset($_GET['p'])){
$_SESSION['producto'][$_SESSION['contador']] = $_GET['p']; 
$_SESSION['contador']++;
}
f(isset($_GET['c'])){
$_SESSION['cantidad'][$_SESSION['contador']] = $_GET['c']; 
}
for ($i=0; $i < $_SESSION['contador']; $i++){
  //esto es lo que nose si estoy bien mal o que onda con la cantidad
  // que ingreso 
  $cab = $_SESSION['cantidad'][$i+1];
  $query = mysqli_query($conect,'SELECT * FROM Productos WHERE 
  id='.$_SESSION['producto'][$i].'');
  while ($fila = mysqli_fetch_array($query)) {
  echo '<td>'.$fila['Nombre'].'</td>';
  echo '<center><input type="number" name="ja" class="la" 
  value='.$cab.'></center>';
?>

Even in these I have no problem but when I want to send the amount I enter in the input I have all kinds of problems because if I capture the variable that contains the value of the input all products are put with the same amount and I do not know how to do I went through a few attempts and the result was this: look at the photo ... the amounts are set but every certain increase in products left blank the amount my question is how I would do to capture the amount and go through the loop without problems since when I did it I put the variable that enters with the index $ i of the loop and the result was that of the photo ...

    
asked by Vinicio Moya Almeida 22.10.2017 в 21:27
source

0 answers