...

View Full Version : Problem with an XML file-generating script



chornbeck
05-05-2006, 06:30 PM
I have written a script that generates an XML file. It works about 80% of the time fine. The rest of the time, I end up with an XML file that isn't "finished", so to speak.

The incomplete XML looks like this:

<marker lat="40.826201" lng="-73.94879" html="Kevin Braxton" label="10031" />
<marker lat="40.826201" lng="-73.94879" html="Joseph L. Brightman" label="10031" />
<marker lat="40.759511" lng="-73.99019" html="Kimberly Ann Williams" label="10036" />
<marker la

It just stops "midstream", in this case, didn't even finish the word "lat".

There just doesn't seem to be a logical reason why this is happening.

Here's the script that generates the XML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<?
if($_POST['submit'])

{

$dbh=mysql_connect ("localhost", "orlandoi_gmap", "gmap") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("orlandoi_gmap");

$InputtedZIP = ($_POST['InputtedZIP']);

$inputCoords = mysql_query("Select LAT, LNG from coord_db where ZIP = '".$InputtedZIP."'") or die(mysql_error());

if(mysql_num_rows($inputCoords)!=0){

while($row = mysql_fetch_array($inputCoords))

{

?>
<tr>
<td><font color=#000000 face="arial">Map has been generated showing all ZIP Codes containing a Festiva Owner within a 50 mile radius of the ZIP code <?php echo $InputtedZIP;?></td>

</tr>

<?php

$inputLAT = $row['LAT'];

$inputLATMINUS = $inputLAT - .3613;

$inputLATPLUS = $inputLAT + .3613;

$inputLNG = $row['LNG'];

$inputLNGPLUS = $inputLNG + .4807;

$inputLNGMINUS = $inputLNG - .4807;

$availZIP = mysql_query("SELECT ZIP from coord_db WHERE (LAT BETWEEN $inputLATMINUS AND $inputLATPLUS) AND (LNG BETWEEN $inputLNGMINUS AND $inputLNGPLUS)") or die(mysql_error());

$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";

$_xml .="<markers>\r\n";

while ($roo = mysql_fetch_array($availZIP)) {

$ZIPArr = $roo['ZIP'];

$ZIPQuery = mysql_query("SELECT ZIPCode, FirstName, LastName from owner_zips WHERE ZipCode = $ZIPArr") or die (mysql_error());

while ($rop = mysql_fetch_array($ZIPQuery)) {



$ownerrop = $rop['ZIPCode'];

$availCOORD = mysql_query("SELECT LAT,LNG from coord_db WHERE ZIP = $ownerrop") or die(mysql_error());

while ($rou = mysql_fetch_array($availCOORD)) {


if ($rou["LAT"]) {

$_xml .="\t<marker lat=\"" . $rou["LAT"] . "\" lng=\"" . $rou["LNG"] . "\" html=\"" . $rop['FirstName'] . " " . $rop["LastName"] . "\" label=\"" . $rop["ZIPCode"] . "\" />\r\n";



}

}

}

}

$_xml .="</markers>";

$file= fopen("results.xml", "w");

fwrite($file, $_xml);

fclose($file);

echo "<a href=\"gmapnames.php?LATCNT=$inputLAT&amp;LNGCNT=$inputLNG\">View the map!.</a>";


}


}

else {echo 'The ZIP code you entered is not a valid U.S. ZIP Code<br><a href="http://www.orlandoinsidersguide.com/gmap/WORKS/form.htm">Click here to try again >>></a>';}


}

?>

</table>

</body>


</html>

fci
05-05-2006, 07:28 PM
maybe it is because of all the nested queries you're using.. mm, try running this instead of the 3 separate queries:


$availZIP = mysql_query("
SELECT oz.ZIPCode, oz.FirstName, oz.LastName, cd.LAT, cd.LANG
FROM coord_db cd
INNER JOIN owner_zips oz ON oz.ZIPCode = cd.ZIP
WHERE (cd.LAT BETWEEN $inputLATMINUS AND $inputLATPLUS)
AND (cd.LNG BETWEEN $inputLNGMINUS AND $inputLNGPLUS)
") or die(mysql_error());


and, $rou["LAT"] .. that can be null.. or, why are you checking it?

chornbeck
05-05-2006, 07:38 PM
Well, I don't really want to mess with the queries since I have it working right (for the most part), I'm really just curious the exact reason something like this might occur...

i.e. If the query structure is problematic, then why does it work sometimes and not others?

fci
05-05-2006, 07:40 PM
have you tried observing the cpu usage of mysql when it has occurred? are the columns indexed?

chornbeck
05-05-2006, 07:45 PM
Not sure what you're asking... I am using a MySQL server that resides on my crappy web host (I'm in the process of switching to a decent one...). Do you think it's simply that my hosting company's MySQL server sucks and crashes occasionally, because it wouldn't surprise me at all if that were the case...

fci
05-05-2006, 07:50 PM
Not sure what you're asking... I am using a MySQL server that resides on my crappy web host (I'm in the process of switching to a decent one...). Do you think it's simply that my hosting company's MySQL server sucks and crashes occasionally, because it wouldn't surprise me at all if that were the case...

sounds possible, does the same problem occur in a local environment (if you have one..) ? part of the reaosn it could be failing is that your queries are inefficient, so refer to my post earlier in this thread to try something that is potentially more optimal (and index columns that are used in the clauses..)

firepages
05-06-2006, 04:23 PM
you may need to convert some characters to thier htmlentity equivalents to stop the XML choking (' & " are usual suspects along with accents etc) ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum