Hi Everybody,
I’m working on a Google Maps mashup that pulls data from a MySQL database with XML written in PHP. I’ve been developing and testing as I go along in Firefox, and it’s working fine, but for some reason Safari won’t read it as XML at all. It works in Firefox and IE, and when I show source in Safari it looks the same, but the page shows blank.
Here’s the code.
[CODE]<?php
require (“/home/cpdpn/public_html/lamp/v3apps/dbinfo.php”);
function parseToXML($htmlStr)
{
$xmlStr=str_replace(“n”,” “,$htmlStr);
$xmlStr=str_replace(“r”,””,$xmlStr);
$xmlStr=str_replace(“&”,’&’,$xmlStr);
$xmlStr=str_replace(‘<‘,’<’,$xmlStr);
$xmlStr=str_replace(‘>’,’>’,$xmlStr);
$xmlStr=str_replace(‘”‘,’"’,$xmlStr);
$xmlStr=str_replace(“‘”,”’,$xmlStr);
return $xmlStr;
}
//sets values for SQL queries
if (isset($_GET[‘pricerange’])){
$pricerangeint = $_GET[‘pricerange’];
}
else {
$pricerangeint = -1;
}
if (isset($_GET[‘restauranttype’])){
$restauranttype = $_GET[‘restauranttype’];
}
else {
$restauranttype = ‘All’;
}
// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $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());
}
// select depending on parameters
if ($pricerangeint != -1 && $restauranttype == ‘All’) {
$query = “SELECT * FROM dguide_map WHERE price_range = ‘$pricerangeint'”;
}
else if ($restauranttype != ‘All’ && $pricerangeint == -1) {
$query = “SELECT * FROM dguide_map WHERE type = ‘$restauranttype'”;
}
else {
$query = “SELECT * FROM dguide_map”;
}
$result = mysql_query($query);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
header(“Content-type: text/xml”);
echo ‘<?xml version=”1.0″ encoding=”UTF-8″?>’;
// Start XML file, echo parent node
echo ‘<markers>’;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
//create and format the HTML for the info box marker
$htmlf = “<div class=’markerbox’>” . “<p class=’restaurantname’>” . $row[“name”] . “</p>”;
if ($row[“image_href”] != null){
$htmlf = $htmlf . “<img src='” . $row[“image_href”] . “‘ class=’restaurantimage’ />”;
}
$htmlf = $htmlf . $row[“excerpt”] . “<br />” . $row[“address”] . “<br /><a href='” . $row[“review_href”] . “‘ target=’_new’>Read a review</a>”;
$htmlf = $htmlf . “</div>”;
// ADD TO XML DOCUMENT NODE
echo ‘<marker ‘;
echo ‘name=”‘ . parseToXML($row[‘name’]) . ‘” ‘;
echo ‘html=”‘ . parseToXML($htmlf) . ‘” ‘;
echo ‘lat=”‘ . $row[‘lat’] . ‘” ‘;
echo ‘lng=”‘ . $row[‘lng’] . ‘” ‘;
echo ‘type=”‘ . $row[‘type’] . ‘” ‘;
echo ‘price_range=”‘ . $row[‘price_range’] . ‘” ‘;
echo ‘address=”‘ . parseToXML($row[‘address’]) . ‘” ‘;
echo ‘restauranttype=”‘ . parseToXML($row[‘type’]) . ‘” ‘;
echo ‘/>’;
}
// End XML file
echo ‘</markers>’;
?>
Can anyone figure it out, I would appreciate it so much. Thanks.