我使用this tutorial從谷歌地圖API生成從MySQL產生從MySQL XML與谷歌腳本
XML這是我得到的錯誤:
警告:
mysql_fetch_assoc()
預計參數1是資源
從我可以告訴我的代碼中,$result
應該通過查詢獲得資源。
有誰知道它爲什麼給這個特定的錯誤?
代碼:
<?php
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
?>
<?php
// connect
$host = "localhost";
$username = 'root';
$psswrd = 'root';
$db = 'sql_maps';
$dbc = mysqli_connect($host, $username, $psswrd, $db);
if(!mysqli_connect_errno()) {
echo 'sueccess'; } else {
die("Database failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
<?php
// Using PHP's domxml Functions to Output XML
// Select all the rows in the markers table
// get data
$query = "SELECT * FROM markers WHERE 1";
// catch resource(collection of database rows)
$result = mysqli_query($dbc, $query);
// check
if($result) {
echo 'success';
} else {
die("connection failed");
}
header("Content-type: application/xml");
while ($row = mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("type", $row['type']);
}
echo $dom->saveXML();
?>
而且,這是什麼WHERE 1
描述SELECT查詢?我假設這是指的ID,然後它會繼續從那裏的循環?
'WHERE 1'是多餘的。值'1'總是爲真,所以'WHERE'選擇表的每一行。離開WHERE,你有相同的結果。 –