I am creating a project in which I applied an autocomplete to a textbox that loads a list from the database. The database has a column "zones_id" and another "destinationall", I intend to obtain the id of the destination selected by the autocomplete, and store it in a variable and then make a comparison with it, but I'm not sure how to execute the query of the id at the same time to store it. I appreciate your attention!
PHP:
<?php
include("conexion.php");
$sql = "select id_zona, destinostodos from destinos order by destinostodos";
$res = mysql_query($sql);
$arreglo_php = array();
if (mysql_num_rows($res)==0)
array_push($arreglo_php, "no hay datos");
else {
while ($palabras = mysql_fetch_array($res)) {
array_push($arreglo_php, $palabras["destinostodos"]);
}
}
?>
Script:
<script type="text/javascript">
$(function() {
var vec_pal = new Array();
<?php
for($p = 0;$p < count($arreglo_php); $p++) { ?>
vec_pal.push('<?php echo $arreglo_php[$p]; ?>');
<?php } ?>
$("#destination").autocomplete({
source: vec_pal
});
});
HTML
<!-- Form: Destino -->
<div id="destino" class="reserva">
<div class="form-group">
<input type="text" placeholder="Destino: Hotel, Villa o Ciudad" class="form-control" name="destination" id="destination">
</div>
</div>