ICC WORLD CUP 2011 WATCH LIVE ONLINE

How to create XML file using PHP

2:57 PM Posted by: Isuru Jayathissa 0 comments

$strXML = "" ; // here insert root or root attribute

// Connect to the DB
$link = connectToDB();


$strQuery = "SELECT DST_IP,
COUNT(DST_IP) AS NumOccurrences
FROM traffic
GROUP BY DST_IP HAVING ( COUNT(DST_IP) > 1 )
ORDER BY NumOccurrences DESC";

$result = mysql_query($strQuery) or die(mysql_error());


if ($result) {
while($ors = mysql_fetch_array($result))
{
$strXML .= ""; // here insert child information
echo "Det GB Accses ";
echo $ors['DST_IP'];

}
}

mysql_close($link);

$strXML .= "
"; // here close the root


$filename = 'artists.xml'; // here put the xml file name
if (is_writable($filename)) {
if (!$handle = fopen($filename, "a+")) {
//fgets($handle);
echo "Cannot open ($filename)";
exit;
}
if (fwrite($handle, $strXML) === FALSE) {
echo "Cannot write to ($filename)";
exit;
}

echo "Success, wrote ($strXML) to ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}

No comments:

Post a Comment

 


2009 Isuru's Blog. All rights reserved.
.
For the more details..,
keijayathissa@gmail.com