Array Data Passage by onclick [duplicated]

1

Good afternoon, I needed help with a topic. I bring the data from an api with curl in php which I keep in an array and that's perfect, I show the data in a table and in that table I have a input button which I need to click, send me the position of the selected array to pedido.php , which receives the array and shows it in a table. I leave a bit of code to see if you can give me a hand. A greeting

Table

<td>
  <img  src="<?php echo $valor['foto'] ; $i++ ;?>" border='0' width='50' height='50' onmouseover="this.width=500;this.height=500" onmouseout="this.width=50;this.height=50">
</td>
<td><?php echo $valor['descripcion']; ?></td>
<td><?php echo $valor['familia'] ;?></td>
<td><?php echo $valor['codigo'] ;?></td>
<td><?php echo $valor['descripcionadicional']; ?></td>
<td><?php if ($valor['precio1'] <= 0) echo "Sin disponibilidad"; else echo $valor['precio1']; ?></td>

Button

<input 
  type="button" 
  class="button" method="POST"
  value="Agregar a pedido" 
  name="Agregar"  
  id ="Agregar" 
  title="Agregar" 
  onclick="my()"
/>
    
asked by Matias Ezequiel Zelaya Blanco 28.01.2017 в 15:10
source

1 answer

1

To start, the value of the array position should be printed next to the table.

EDIT: Change part of the code to have more info.

<tr>
    <td>
        <img
            src="<?php echo $valor['foto'] ; $i++ ;?>"
            border='0' width='50' height='50'
            onmouseover="this.width=500;this.height=500"
            onmouseout="this.width=50;this.height=50"
        />
    </td>
    <td><?php echo $valor['descripcion']; ?></td>
    <td><?php echo $valor['familia'] ;?></td>
    <td><?php echo $valor['codigo'] ;?></td>
    <td><?php echo $valor['descripcionadicional']; ?></td>
    <td>
        <?php
            if ($valor['precio1'] <= 0)
                echo "Sin disponibilidad";
            else
                echo $valor['precio1'];
        ?>
    </td>
    <td><button data-pos="<?php echo $posicion_en_array;?>">ENVIAR</button></td>
</tr>

Then, in onclick would be something like that.

$("td > button").on("click",function(){
     var pos = $(this).attr("data-pos");
     $.post("tu-pagina.php",{"posicion":pos},function(){
             //-- Hacer algo cuando termine el envio
     })
})

On the other page you receive the information:

$pos_array = $_REQUEST["posicion"]; //-- Posicion del array. Previamente a esta linea tenes que tener cargado el array.
    
answered by 28.01.2017 в 15:50