I wonder whether someone can help me please.
I’m using the following script to load marker data into my map.
<?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();
?>
I’d now like to extend the functionality of it further, by adding a new field that converts a numeric value to text. To be more precise if the ‘totalfinds’ figure is zero then I would like a field that says ‘No items found’ and if the value is greater than zero then this would return the text ‘Items Found’.
From what I’ve read, I think that I’ll need to do this via an ‘If’ Statement. I am a little new to this, but could someone perhaps confirm for me please whether this is the best way to go about it.
Many thanks
Yes, you can use
if, ieinstead of