<categories>
<category title="Audi">
<courses><courses>
</category>
</categories>
Code: Select all
<?php
header("Content-type: text/xml");
$host = "#";
$user = "#";
$pass = "#";
$database = "#";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM stock ORDER BY Make ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<lineup>\n";
$xml_output .= "<catergories>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<category>\n";
$xml_output .= "\t\t<title>" . $row['Make'] . "</title>\n";
// Escaping illegal characters
$row['Make'] = str_replace("&", "&", $row['Make']);
$row['Model'] = str_replace("<", "<", $row['Make']);
$row['Price'] = str_replace(">", ">", $row['Make']);
$row['Features'] = str_replace("\"", """, $row['Make']);
$xml_output .= "\t\t<text>" . $row['Make'] . "</text>\n";
$xml_output .= "\t</category>\n";
}
$xml_output .= "</catergories>";
$xml_output .= "</lineup>";
echo $xml_output;
?>