Ver Mensaje Individual
  #5 (permalink)  
Antiguo 10/12/2015, 08:36
jlopezisern
 
Fecha de Ingreso: mayo-2014
Mensajes: 45
Antigüedad: 10 años
Puntos: 0
Respuesta: Error en código de cálculo de distancias

El tema es que si filtro por tipo:
$result = mysql_query("select id_cliente, nombre, tipo, precio, icono1, localidad FROM restauracion WHERE tipo IN('$tipos_trim')");
Funciona perfectamente.
Si filtro por distancia:
$result = mysql_query('SELECT id_cliente, nombre, tipo, precio, icono1, localidad, (6371 * ACOS(
SIN(RADIANS(lat))
* SIN(RADIANS(' . $latitud . '))
+ COS(RADIANS(lng - ' . $longitud . '))
* COS(RADIANS(lat))
* COS(RADIANS(' . $latitud . '))
)
) AS distance
FROM restauracion
WHERE (lat BETWEEN ' . $box['min_lat']. ' AND ' . $box['max_lat'] . ')
AND (lng BETWEEN ' . $box['min_lng']. ' AND ' . $box['max_lng']. ')
HAVING distance < ' . $distanciausuario . '
ORDER BY distance ASC');
Funciona perfectamente.
Pero si filtro por tipo y distancia:
$result = mysql_query('SELECT id_cliente, nombre, tipo, precio, icono1, localidad, (6371 * ACOS(
SIN(RADIANS(lat))
* SIN(RADIANS(' . $latitud . '))
+ COS(RADIANS(lng - ' . $longitud . '))
* COS(RADIANS(lat))
* COS(RADIANS(' . $latitud . '))
)
) AS distance
FROM restauracion
WHERE tipo IN('$tipos_trim')
AND (lat BETWEEN ' . $box['min_lat']. ' AND ' . $box['max_lat'] . ')
AND (lng BETWEEN ' . $box['min_lng']. ' AND ' . $box['max_lng']. ')
HAVING distance < ' . $distanciausuario . '
ORDER BY distance ASC');
Da error en la límea WHERE tipo IN('$tipos_trim') y en la ORDER BY distance ASC'); en Dreamweaver.