Code:
<?php
$datoBuscar = $_GET["term"];
$conexion = mysql_connect("localhost", "root", "");
mysql_select_db("ap_contable");
$ssql = "SELECT provincia_id, nombre, codigopostal FROM ciudades WHERE codigopostal LIKE '%" . $datoBuscar . "%' LIMIT 50";
$rs = mysql_query($ssql, $conexion);
$arrayElementos = array();
while ($fila = mysql_fetch_array($rs)){
echo $fila[provincia_id];
$queryp = "SELECT nombre FROM provincias WHERE id = '$fila[provincia_id]' LIMIT 1";
$resultp = mysql_query($queryp, $conexion);
$foundp = mysql_fetch_array($resultp);
echo $foundp['nombre'];
$row['prov'] = $foundp['nombre'];
$row_set[] = $row;
}
echo json_encode($row_set);
?>
Example: http://localhost/Contable/autocompletecod.php?term=3269
The output of this is as follows
6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos6Entre Ríos[{"prov":null},{"prov":null},{"prov":null},{"prov": null},{"prov":null},{"prov":null},{"prov":null},{" prov":null},{"prov":null},{"prov":null},{"prov":nu ll},{"prov":null},{"prov":null},{"prov":null},{"pr ov":null},{"prov":null},{"prov":null}]
I put the ECHO intentionally to see if it is taking the data from the MySQL database and if it gets it. The problem is that when I assign it to the array $row['prov'] = $foundp['nombre']; Where is the problem? Where it says NULL should say Entre Rios