Qualcuno mi può dare una indicazione se il codice di seguito è corretto e come faccio a creare un file XML da controllare da subito?
<?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
$mysql_host = "server my sql";
$mysql_user = "user";
$mysql_pwd = "userpwd";
$mysql_db = "dbase";
//$mysql_port = 3306;
//$max_time = 80;
$connessione = mysql_connect($mysql_host,$mysql_user,$mysql_pwd)
or die ("Impossibile collegarsi al Server");
mysql_select_db($mysql_db)
or die ("ERRORE: il database richiesto non esiste" . $mysql_db);
// Select all the rows in the markers table
$stringa = "WHERE Livello BETWEEN 30 AND 80";
$query1 = 'SELECT * FROM roma_P1' . $stringa;
$result = mysql_query($query1);
$numRows = mysql_num_rows($result);
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("serial", $row['Serial']);
$newNode->setAttribute("livello", $row['Livello']);
$newNode->setAttribute("batteria", $row['Batteria']);
$newNode->setAttribute("P_id", $row['P_id']);
$newNode->setAttribute("lat", $row['CoordY']);
$newNode->setAttribute("lng", $row['CoordX']);
$newNode->setAttribute("tipo", $row['TipoRifiuto']);
$newNode->setAttribute("data", $row['Data']);
$newNode->setAttribute("ora", $row['Ora']);
$lvl = $row['Livello'];
if ($lvl < '25') {
$flag='verde';
}elseif ($lvl >= '25' and $lvl <'50') {
$flag='giallo';
}elseif ($lvl >= '50' and $lvl <'75') {
$flag='arancione';
}elseif ($lvl >= '75' and $lvl <'98') {
$flag='rosso';
}elseif ($lvl >= '98') {
$flag='critico';
}
$newnode->setAttribute("livello2",$flag);
}
echo $dom->saveXML();
//echo $dom->printXML();