$db->close(); } function distanceBetweenTwoPoints($P1lat, $P1lon, $P2lat, $P2lon) { $sideA = abs($P1lon - $P2lon); $sideB = abs($P1lat - $P2lat); return sqrt($sideA * $sideA + $sideB * $sideB); } function getShops($shopFileUrl) { global $shopArray; $json_string = file_get_contents($shopFileUrl); $shopArray = json_decode($json_string, true); } getStations(); getShops($shopFileUrl); foreach ($shopArray as $key => $shop) { # code... $shopName = $shop['ourName']; $shopLat = $shop['lat']; $shopLng = $shop['lng']; $distance = PHP_INT_MAX; $nearestStation; foreach ($stationArray as $key => $station) { # code... $stationLat = $station['stationLat']; $stationLng = $station['stationLong']; $calculatedDistance = distanceBetweenTwoPoints($shopLat, $shopLng, $stationLat, $stationLng); if ($distance >= $calculatedDistance) { # code... $distance = $calculatedDistance;
<div class="table-responsive"> <table class="table table-striped table-bordered table-hover text-center" id="dataTables-example"> <thead> <tr> <th><div align="center">ลำดับ</div></th> <th><div align="center">รหัสร้านค้า</div></th> <th><div align="center">ชื่อร้านค้า</div></th> <th><div align="center">เบอร์โทร</div></th> <th><div align="center">ภาค</div></th> <th><div align="center">จังหวัด</div></th> <th><div align="center">การกระทำ</div></th> </tr> </thead> <tbody> <?php $getShops = getShops(); $i = 0; foreach ($getShops as $value) { $i++; $val_idshop = $value['idshop']; $val_shop_code = $value['shop_code']; $val_name_shop = $value['name_shop']; $val_tel_shop = $value['tel_shop']; $val_name_region = $value['name_region']; $val_name_province = $value['name_province']; ?> <tr> <td><?php echo $i; ?> </td>