가 삽입 할 정확히 모른 채, 희망이 방법은 당신을 위해 작동합니다
public function insert_locations($locations, $new_locations) {
// make them into collection if not already
$locations_coll = Collection::make($locations);
// chunk the database insert if there are too many records in the collection
$locations_coll->chunk(500)->each(function($chunk1) {
$inserts = '';
// loop through locations
foreach($chunk1 as $location1) {
foreach($new_locations as $location2) {
// if locations are the same then skip
if($location1==$location2) continue;
// add to bulk inserts
$inserts .= '(' . $location1 . '-' . $location2 . '), ' . PHP_EOL;
}
}
// do the bulk insert
try {
DB::insert("INSERT INTO your_table (`locations`) VALUES $inserts");
} catch (Exception $e) {
print_r([$e->getMessage()]);
}
});
}
// get your existing locations
$locations = ['Berlin', 'Hamburg', 'Stuttgart', 'Hannover', 'Heidelberg', 'Bern' ...];
// and get your new locations
$new_locations = ['Berlin', 'Hamburg', 'Stuttgart', 'Hannover', 'Heidelberg', 'Bern' ...];
// call the method
insert_locations($locations, $new_locations);
// get more new locations
$new_locations = ['Bayern'];
// call the method again
insert_locations($locations, $new_locations);
당신이 삽입 중복 당신이 뭔가를 사용할 수를 피하려면 귀하의 SQL 문을 이렇게 :
DB::insert("INSERT INTO your_table (`locations`) VALUES $inserts ON DUPLICATE KEY UPDATE `locations`=VALUES(`locations`)");
그냥 생각할 수있는 모든 가능성에 대한 경로를 만들 필요가 결정 궁금해? 루트를 읽어야합니다. – TimBrownlaw
@TimBrownlaw 질문에 감사드립니다. 내가 일하는 택시 서비스는 가격에 킬로미터를 곱하면 안된다. 80x80 위치와 킬로미터에 가격을 곱한 정적 가격이 필요하다. –
@TimBrownlaw 그리고 OSRM, Google Maps 및 Mapbox 패키지를 만들기로 결정했다. 사용자. –