|
<?php require_once('Connections/connSQL.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; }
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } }
mysql_select_db($database_connSQL, $connSQL); $query_RecHotel = "SELECT * FROM hoteldata"; $RecHotel = mysql_query($query_RecHotel, $connSQL) or die(mysql_error()); $row_RecHotel = mysql_fetch_assoc($RecHotel); $totalRows_RecHotel = mysql_num_rows($RecHotel);
//get_contents($url) 取得遠端網頁內容函數 function get_contents($url){ $url = str_replace(" ", "%20", $url); $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch); curl_close($ch);
return $output; }
$data=get_contents('http://data.taipei.gov.tw/opendata/apply/json/RjQzRThDNjUtMzU3OS00MTU5LUEwOUEtMUI2NzFDOTE5NDcz'); $result = json_decode($data);
foreach($result as $key => $value) { if($value) { mysql_query("INSERT INTO taipeihotel.hoteldata (name ,certification_category ,tel ,display_addr ,poi_addr ,traffic_info ,X ,Y)VALUES ('$value->name' , '$value->certification_category', '$value->tel', '$value->display_addr', '$value->poi_addr', '$value->traffic_info', '$value->X', '$value->Y');"); } }
header("Location:index.php");
mysql_free_result($RecHotel); ?>
|