get users who live within 10 km radius of the current logged in user codeigniter 3 |
Hello
am trying to get all user who are within 10 km radius of the current logged in user so i tried getting only the addresses i get them but now i want to link the addresses with their owners so that i can display the users names etc. so to get the addresses i used this code: PHP Code: function Addresses($CurrentUserAdd){ PHP Code: print_r(Addresses($this->session->userdata('address'))); PHP Code: ( PHP Code: [0] => 1.31 PHP Code: [1] => 1.85 PHP Code: [2] => 3.15 PHP Code: [3] => 0 PHP Code: [4] => 1.84 PHP Code: [5] => 1.54 PHP Code: ) PHP Code: function Addresses($CurrentUserAdd){ Please help thanks in advance. Am using mssql server so i saw STDistance function but i dont know if this is doable for many users
First, get all "other" users from your database, i.e. all users where id is not the id of the current user. Get the results in an array named $users.
Also create a new empty array, named $nearby_Users. Then, loop through all rows in the users array. Calculate the distance between the user's location and the location of the "current user", with your function getDistance(). If the distance is 10 km or less, add that user's data to the $nearby_Users array. After the loop, do whatever you need with the $nearby_Users array. There's no need to make a complicated SQL query to get the final result. (10-06-2019, 09:56 AM)Wouter60 Wrote: First, get all "other" users from your database, i.e. all users where id is not the id of the current user. Get the results in an array named $users.Thank you @Wouter60. let me impliment that |
Welcome Guest, Not a member yet? Register Sign In |