Reputation: 9664
Trying to run some SQL with no luck, trying to select data from two tables where a condition is true.
The tables are driver_details and locations. Both tables have the column user_id, and I want to get data from both based on the matched user_id from the between part. (that select statement works and returns ID's);
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))
I am getting the error: Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\vector\www\scripts\getDriversInRange.php on line 33
Upvotes: 0
Views: 105
Reputation: 6393
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
This is basically a more complete example of what BWS posted.
Upvotes: 1
Reputation: 3836
You need to RELATE the 2 tables being JOINed using SOMETHING that's common in both tables, which is used to connect them ... you mention user_id
...
FROM driver_details
INNER JOIN locations
ON driver_details.user_id = locations.user_id
WHERE ...
Upvotes: 2