Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Problem with an XML file-generating script

    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:
    Code:
    <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:
    PHP Code:
    <!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>";

    $filefopen("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>

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe it is because of all the nested queries you're using.. mm, try running this instead of the 3 separate queries:
    PHP Code:
    $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?
    Last edited by fci; 05-05-2006 at 06:30 PM.

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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?

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have you tried observing the cpu usage of mysql when it has occurred? are the columns indexed?

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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...

  • #6
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chornbeck
    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..)

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,048
    Thanks
    10
    Thanked 93 Times in 91 Posts
    you may need to convert some characters to thier htmlentity equivalents to stop the XML choking (' & " are usual suspects along with accents etc) ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •