In my previous projects using the jquery autocomplete. This function consisted of two parts
Number one.jquery function
<script>
$(function() {
$(".auto").autocomplete({
source: "search_producto.php",
minLength: 1,
select: function(event, data) {
$("#codigo").val(data.item.ide);
$("#iva").val(data.item.iva);
$("#descuento").val(data.item.descue);
$("#disponible").val(data.item.dispo);
$("#precio").val(data.item.precio);
$("#unidad").val(data.item.unidad);
$("#producto").val(data.item.value);
$(".auto").val(data.item.value);
$("#cant").focus();
},
});
});
</script>
number two The file search_producto.php
<?php
if (isset($_GET['term'])){
$return_arr = array();
try {
$db_username = "SPOLS";
$db_password = "SPOLS";
$db = "oci:dbname=JEIEL/XE";
$conn = new PDO($db,$db_username,$db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT P.PROD_CODIGO, P.PROD_NOMBRE, P.PROD_CODIG1, P.PROD_UNIDAD ,PROD_CODIG2,PROD_IVA FROM MAE_PROD P WHERE P.PROD_ESTADO='1' AND P.PROD_TIPOXX='PRO' AND P.PROD_NOMBRE LIKE :term");
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));
while($row = $stmt->fetch()) {
$return_arr[] = array('value' => $row['PROD_NOMBRE'], 'nombreproducto' => $row['PROD_NOMBRE'], 'ide' => $row['PROD_CODIGO'], 'unidad' => $row['PROD_UNIDAD'], 'precio' => '2.25', 'descuento' => '0.00', 'iva' =>$row['PROD_IVA'], 'serial' => $row['PROD_CODIG1'], 'barra' => $row['PROD_CODIG2'],'dispo'=>'0.00');
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
header('Content-type: application/json');
echo json_encode($return_arr);
}
?>
The second file is a class that stores data me my table in an array that sent as json. How do I create the array to store data from my table?