解决。见下文。
初步问题:
我需要从mySQL表中的数组字段(643844X2X48)中提取lat和lon,其中数据如下所示:
56.559482483762245; -104.0625 ;; SK; CA; S0J
我尝试了mysqli和pdo代码但失败了。
这个php / mysql代码使用最终循环lat值更新所有lat字段:
$sql = "SELECT 643844X2X48 from `reg_survey_643844`";
$array = mysql_query($sql);
while($row=mysql_fetch_assoc($array)){
foreach($row as $value){
$result= explode(";", $value);
$slice= (array_slice($result,0,1));
$lat = array_shift(array_values($result));
mysql_query("UPDATE reg_survey_643844 SET lat = '$lat'");
}
}
我做错了什么?
更新:
这是工作代码。
$query = "SELECT * FROM reg_survey_643844 ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$resultGeo= explode(";", $row["643844X2X48"]);
$lat = $resultGeo[0];
$lon = $resultGeo[1];
$city = $resultGeo[2];
$state = $resultGeo[3];
$countryCode = $resultGeo[4];
$zip = $resultGeo[5];
$getid = $row['id'];
$siteName = $row['643844X2X12'];
$query = mysql_query("UPDATE reg_survey_643844
SET siteName = '$siteName', lat = '$lat', lon = '$lon', city = '$city', state = '$state', countryCode = '$countryCode', zip = '$zip'
WHERE id = '$getid'");
}
答案 0 :(得分:1)
试试这个
$sql = "SELECT 643844X2X48 from `reg_survey_643844`";
$array = mysql_query($sql);
while($row=mysql_fetch_assoc($array)){
$result= explode(";", $row["your data"]);
$lat = $result[0];
mysql_query("UPDATE reg_survey_643844 SET lat = '$lat' whrere your conditions");
}