我正在使用mysql_query从mysql中获取记录,但它没有返回确切的记录,而我在phpmyadmin中运行相同的查询时返回正确的记录。
$sql = "SELECT * , (3959 * acos(cos(radians(28.5355161)) * cos(radians(latitude)) * cos( radians(longitude) - radians(77.39102649999995)) + sin(radians(28.5355161)) * sin(radians(latitude)))) AS distance FROM businesses HAVING distance < 100 ORDER BY distance DESC LIMIT 0,10";
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
$arr[]=$row;
}
echo '<pre>';print_r($arr);
仅返回单个记录:
Array
(
[0] => Array
(
[id] => 8
[name] => sayeed
[address] => Test
[contact_number] => 865335312
[avatar] => 4f38030400f4e62bbc3cb9aa4e23ac45.jpg
[route_short] =>
[route_long] =>
[postal_code_short] =>
[postal_code_long] =>
[neighborhood_short] =>
[neighborhood_long] =>
[street_number_short] =>
[street_number_long] =>
[country_short] => IN
[country_long] => India
[locality_short] => Noida
[locality_long] => Noida
[administrative_area_level_1_short] => UP
[administrative_area_level_1_long] => Uttar Pradesh
[administrative_area_level_2_short] => Gautam Bud
[administrative_area_level_2_long] => Gautam Buddh Nagar
[formatted_address] => Noida, Uttar Pradesh, India
[latitude] => 28.5355161
[longitude] => 77.39102649999995
[time_created] => 0000-00-00 00:00:00
[description] => Test
[contact_email] => mohd.sayeed@udaantechnologies.com
[website] => www.udaantechnologies.com
[category] => 1
[distance] => 0.00005899369716644287
)
)
如果我使用phpmyadmin运行相同的查询,则返回4条记录。
答案 0 :(得分:0)
您的查询在乘法过程中有enter code here
!这应该会导致错误。尝试删除它。
SELECT * , (3959 * acos(cos(radians(28.5355161)) * `enter code here`cos(radians...
请改为尝试:
$sql = "
SELECT *,
(3959 *
acos(
cos(radians(28.5355161)) *
cos(radians(latitude)) *
cos(radians(longitude) - radians(77.39102649999995)) +
sin(radians(28.5355161)) *
sin(radians(latitude))
)
) AS distance
FROM businesses
HAVING distance < 100
ORDER BY distance DESC LIMIT 0,10";
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
echo '<pre>';
print_r($arr);
echo '</pre>';