尝试运行一些没有运气的SQL,尝试从条件为真的两个表中选择数据。
表格是driver_details和位置。两个表都有user_id列,我想根据部分之间匹配的user_id从两者中获取数据。 (该选择语句有效并返回ID);
SELECT driver_details.firstName,
locations.lat,
locations.lng
FROM driver_details
INNER JOIN locations
WHERE user_id =
(SELECT user_id FROM locations WHERE
(lat BETWEEN 0 AND 5) AND
(lng BETWEEN 0 AND 5))
我收到错误: 致命错误:在第33行的C:\ xampp \ htdocs \ vector \ www \ scripts \ getDriversInRange.php中的非对象上调用成员函数bind_param()
答案 0 :(得分:2)
您需要使用两个表中常见的SOMETHING来关联正在联接的2个表,这些表用于连接它们...您提到user_id
...
FROM driver_details
INNER JOIN locations
ON driver_details.user_id = locations.user_id
WHERE ...
答案 1 :(得分:1)
SELECT d.firstName,
l.lat,
l.lng
FROM driver_details d
INNER JOIN locations l ON d.user_id = l.user_id
WHERE l.lat BETWEEN 0 AND 5
AND l.lng BETWEEN 0 AND 5
这基本上是BWS发布的更完整的例子。