gpt4 book ai didi

php - 不能修改url参数

转载 作者:行者123 更新时间:2023-11-29 03:21:37 28 4
gpt4 key购买 nike

请问大家这是怎么了?我已经编写了以下代码,用于使用 mysql 数据库列 degree_n 、 minute_n 等更新 url 参数“lat”和“lng”,但没有发生。我想要的是每次运行此脚本时,应该使用 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";

?>

最佳答案

使用以下代码从 geonames.com 获取经纬度

<?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();

?>

关于php - 不能修改url参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43534937/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com