나는 누군가가 나를 도울 수 있는지 궁금해.If Statement in PHP Script
마커 데이터를 내지도에로드하는 데 다음 스크립트를 사용하고 있습니다.
<?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'수치가 0이면 'No items found'라고 쓰여진 필드를 원하고 값이 0보다 크면 'Items Found'텍스트를 반환합니다.
내가 읽은 것으로부터, 나는 'If'진술을 통해 이것을 할 필요가 있다고 생각한다. 나는 이것에 조금 새로운지만, 누군가가 아마도 나를 위해 그것을 확인하는 가장 좋은 방법인지 확인해 줄 수 있습니다.
많은 감사
모두 감사합니다. 정확히 내가 무엇을 찾고 있었는지. 친절합니다. – IRHM
환영합니다 :) ----- – MeLight