I have below select statement which is returning Nearby Available user_id's with some other column value
$sql="(SELECT
user_location.*,
driver_location.user_id as user_id,
( 3959 * acos( cos( radians(37.4219983) ) * cos( radians( driver_location.latitude ) ) * cos( radians( driver_location.longitude ) - radians(-122.0844) ) + sin( radians(37.4219983) ) * sin(radians(driver_location.latitude)) ) ) AS distance
FROM user_location, driver_location
HAVING distance >= 0)";
Now For each user_id
from above query I need to Insert data to request
table with some other details.For each user_id there will be a separate row with other details.I have tried below as an array but it't not saving any data
foreach ($sql as $key => $value) {
$data[] = [
'pickup_latitude' => $pickup_lat,
'pickup_longitude' => $pickup_lan,
'car_id' => $car_id,
'user_id' => $value->user_id,
'user_mobile' =>$umobile
];
} //for loop
$columns = implode(", ",array_keys($data));
$escaped_values = array_map('mysql_real_escape_string', array_values($data));
$values = implode(", ", $escaped_values);
$stmt = $con->prepare("INSERT INTO `request`($columns) VALUES ($values)");
$stmt->execute();