我想知道是否有人可以幫助我請。如果在PHP腳本語句
我正在使用以下腳本將標記數據加載到我的地圖中。
<?php
require("phpfile.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ("hostname", $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "select l.locationid, f.locationid, l.locationname, l.address, l.osgb36lat, l.osgb36lon, count(f.locationid) as totalfinds from detectinglocations as l left join finds as f on l.locationid=f.locationid group by l.locationid";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("locationid",$row['locationid']);
$newnode->setAttribute("locationname",$row['locationname']);
$newnode->setAttribute("address",$row['address']);
$newnode->setAttribute("osgb36lat",$row['osgb36lat']);
$newnode->setAttribute("osgb36lon",$row['osgb36lon']);
$newnode->setAttribute("totalfinds",$row['totalfinds']);
}
echo $dom->saveXML();
?>
我現在想通過添加一個將數值轉換爲文本的新字段來進一步擴展它的功能。更確切地說,如果'totalfinds'的數字爲零,那麼我希望有一個字段顯示'找不到任何項目',如果該值大於零,那麼這將返回'找到物品'文本。
從我讀過的內容來看,我認爲我需要通過'If'聲明來做到這一點。我對此有點新,但也許有人可能會確認這是否是最好的方式。
非常感謝
全部,非常感謝您的幫助。正是我在找什麼。親切的問候。 – IRHM
歡迎:) ----- – MeLight