无法修改网址参数

时间:2017-04-21 05:56:28

标签: php mysql

这里的男人有什么不对? 我写了以下代码来更新url参数" lat"和" lng"使用mysql数据库列degree_n,minute_n等但没有发生。我想要的是每当这个脚本运行时,应该使用MySQL数据库中的值来修改url

<?php
$servername = "localhost";
$username = "id1116502_track_data";
$password = "***";
$dbname = "****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 } 
$url = "http://ws.geonames.org/countryCodeJSON?lat=<?php
$servername = "localhost";
$username = "id1116502_track_data";
$password = "***";
$dbname = "****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 } 
$sql = "SELECT  degree_n, minute_n FROM coordinates  ORDER BY id DESC limit 1 ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        print " " .$row["degree_n"]. "." .$row["minute_n"]. " ";
    }
} else {
    echo "0 results";
}
 $conn->close();
?>&lng=<?php
$servername = "localhost";
$username = "id1116502_track_data";
$password = "****";
$dbname = "****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 } 
$sql = "SELECT degree_e, minute_e FROM coordinates  ORDER BY id DESC limit 1 ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        print " " .$row["degree_e"]. "." .$row["minute_e"]. " ";
    }
} else {
    echo "0 results";
}
 $conn->close();
?>&username=****8";
echo "$url";

?>

1 个答案:

答案 0 :(得分:0)

使用以下代码从geonames.com获取lat long

<?php
$servername = "localhost";
$username = "id1116502_track_data";
$password = "********";
$dbname = "id1116502_kk";

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 }
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
//remove limit 1 is you want multiple data.  
$sql = "SELECT degree_e, minute_e FROM coordinates  ORDER BY id DESC limit 1 "; 
$result = $conn->query($sql);
$deg_e = "";
$min_e = "";
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $deg_e = $row["degree_e"];
        $min_e = $row["minute_e"];
        $url = file_get_contents('http://ws.geonames.org/countryCodeJSON?lat='.$deg_e.'&lng='.$min_e.'&username=demo');
        var_dump($url);
    }
} else {
    echo "0 results";
}
$conn->close();

?>