I am trying to loop through my MySQL data and clean it up for my XML but I am trying to do it the most efficient way possible. Below is my code so far. This code only cleans one field CompanyName I want to clean all 8 fields if the same loop if possible.
header("Content-type: text/xml");
$SQL_query = "SELECT * FROM COMPANYINFO ORDER BY CompanyName DESC";
$resultID = mysql_query($SQL_query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<markers>\n"; w
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
// Escaping illegal characters
$row['CompanyName'] = str_replace("&", "&", $row['CompanyName']);
$row['CompanyName'] = str_replace("<", "<", $row['CompanyName']);
$row['CompanyName'] = str_replace(">", ">", $row['CompanyName']);
$row['CompanyName'] = str_replace("\"", """, $row['CompanyName']);
$xml_output .= "\t\t<marker name='.$row['CompanyName']."' address='".$row['Address_1']."' phone='".$row['Phone']."' lat='".$row['Lat_Info']."' lng='".$row['Long_Info']."' county='".$row['County']."'/>\n";
}
$xml_output .= "</markers>";
echo $xml_output;
Run any strings that you need to put in XML through
htmlspecialchars()and you should be fine.As to dealing with the results, you can use a
foreachloop to go through the array.Put together, you get: