Last active
July 5, 2017 08:30
-
-
Save mr5z/ee17407bbf9f623c1f91c00ef0501c55 to your computer and use it in GitHub Desktop.
get user by id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getUserById($userId) { | |
$sql = "SELECT users.*, | |
COALESCE((SELECT locations.friendlyAddress | |
FROM locations | |
WHERE locations.userId = users.id | |
ORDER BY locations.dateGather | |
DESC LIMIT 1), 'Unavailable') lastKnownLocation, | |
COALESCE((SELECT CONCAT(locations.latitude, ',', locations.longitude) | |
FROM locations | |
WHERE locations.userId = users.id | |
ORDER BY locations.dateGather | |
DESC LIMIT 1), '') position | |
FROM users | |
WHERE users.id = $userId"; | |
return query($sql); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment