我有從XML導入數據到SQL表的問題。該XML看起來是這樣的:從XML導入數據到數據庫使用PHP循環
<MeasuringPoints>
<MeasuringPoint ID="BaseStation" LastChange="2013-05-20T12:15:03.837">
</MeasuringPoint>
<MeasuringPoint ID="MiddleStation" LastChange="2012-08-01T11:47:33.160">
</MeasuringPoint>
<MeasuringPoint ID="MountainStation" LastChange="2013-05-20T12:15:03.840>
</MeasuringPoint>
</MeasuringPoints>
使用PHP(foreach
循環)
foreach($skiarea->MeasuringPoints->MeasuringPoint as $measuring) {
$MEASURING_POINTS = $measuring['ID'];
$MEASURING_LAST_CHANGE = $measuring['LastChange'];
}
我得到的輸出這樣的數據:
BaseStation - 1369052103
MiddleStation - 1343821653
MountainStation - 1369052103
我試圖插入值batabase
mysql_query("
INSERT INTO database_name SET
base_station_last_change = '$MEASURING_LAST_CHANGE[0]',
middle_station_last_change = '$MEASURING_LAST_CHANGE[1]',
mountain_station_last_change = '$MEASURING_LAST_CHANGE[2]',
") OR die(mysql_error());
但是這段代碼沒有工作。只導入一個值。
如何將這些數據插入到sql數據庫字段?
爲什麼你在插入查詢設置字段名稱????? –