I have a bootstrap modal to which I load data from my database in mysql what I want it to do, is that by clicking on the add button I add the product of the modal row to a table in php in another page and when I gave it to another product, I added the following and so on. What it does now is load the first data that it sent to it and later when loading the second it deletes the one that previously sent, then what I want is that it makes a list. I appreciate any help.
What I need is that you send me the data of the row here, in this table. But when sending the first data the next one deletes the first as if it will be updated. What I need is that you list them.
I enclose the code of the file agreg.php
<?php
require_once("../clases/conexion.php");
$id = $_POST['codigo'];
$c = $_POST['canti'];
$sql = "select * from tbl_producto where codigo = '$id'";
$result = mysqli_query($con, $sql);
?>
<table class="table">
<tr>
<th class='text-center'>CODIGO</th>
<th class='text-center'>CANT.</th>
<th>DESCRIPCION</th>
<th class='text-right'>PRECIO UNIT.</th>
<th class='text-right'>PRECIO TOTAL</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result)) {
$codigo=$row['codigo'];
$producto=$row['nombre'];
$marca=$row['marca'];
$precio=$row['precio'];
$preciofinal = $precio*$c;
?>
<tr>
<td class="text-center"><?php echo $codigo; ?></td>
<td class="text-center"><?php echo $c; ?></td>
<td><?php echo $producto.' '.$marca; ?></td>
<td class="text-right"><?php echo $precio; ?></td>
<td class="text-right"><?php echo $preciofinal; ?></td>
<td class='text-center'><a href="#" onclick=""><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
<?php
}
?>
<tr>
<td class='text-right' colspan=4>SUBTOTAL $</td>
<td class='text-right'></td>
<td></td>
</tr>
<tr>
<td class='text-right' colspan=4>IGV $</td>
<td class='text-right'></td>
<td></td>
</tr>
<tr>
<td class='text-right' colspan=4>TOTAL $</td>
<td class='text-right'></td>
<td></td>
</tr>
</table>
This is the function with which I sent you the data for the query
function agregar(id){
var cant = document.getElementById('cantidad_'+id).value;
$.ajax({
type: 'POST',
url: "servlet/agregaraPHP.php",
data: "codigo="+id+"&canti="+cant,
success: function (r){
$("#resultados1").html(r);
}
});
}
And this is the code of the bootstrap modal
<!-- Modal Busca Producto-->
<div class="modal fade" id="AgregarPro" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Buscar productos</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control" id="filtrar" placeholder="Buscar productos">
</div>
<a href="#" id="bus"><i class='glyphicon glyphicon-search'></i> Buscar</a>
</div>
</form>
<div class="outer_div">
<?php
require './clases/conexion.php';
$sql = "select * from tbl_producto";
$result = mysqli_query($con, $sql);
?>
<div class="table-responsive">
<table class="table">
<tbody class="buscar">
<tr class="warning">
<th>Código</th>
<th>Producto</th>
<th>Marca</th>
<th><span class="pull-right">Cant.</span></th>
<th><span class="pull-right">Precio</span></th>
<th class='text-center' style="width: 36px;">Agregar</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result)) {
$codigo=$row['codigo'];
$producto=$row['nombre'];
$marca=$row['marca'];
$cantidad=$row['cantidad'];
$precio=$row['precio'];
?>
<tr>
<td><?php echo $codigo; ?></td>
<td><?php echo $producto; ?></td>
<td><?php echo $marca; ?></td>
<td class='col-xs-1'>
<div class="pull-right">
<input type="text" class="form-control" style="text-align:right" id="cantidad_<?php echo $codigo; ?>" value="<?php echo $cantidad; ?>">
</div>
</td>
<td class='col-xs-2'>
<div class="pull-right">
<input type="text" class="form-control" style="text-align:right" id="precio" value="<?php echo $precio; ?>">
</div>
</td>
<td class='text-center'>
<a class='btn btn-info'href="#" onclick="agregar(<?php echo $codigo; ?>)"><i class="glyphicon glyphicon-plus"></i></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div><!-- Datos ajax Final -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
Please, I thank you for your help.