Web Analytics Made Easy -
StatCounter please help me to creat an xml file from several db queries - CodingForum

Announcement

Collapse
No announcement yet.

please help me to creat an xml file from several db queries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • please help me to creat an xml file from several db queries

    Hi All,

    i am trying to create an xml file from several db queries but im having a few problems.

    here is my code
    PHP Code:
    <?php require_once('dbinfo.php');?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
            <?php
            $file
    fopen("index_latest_results.xml""w");
            
    $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
             
    $_xml .="<site>\r\n";
            
                    
    $query mysql_query("
                    SELECT filmID as id, filmName as name, filmBinding as binding, filmThumbIMG as img, filmReleaseDate as releasedate 
                    FROM tbl_dvds 
                    WHERE filmReleaseDate >= curdate() and filmReleaseDate <= DATE_ADD(curdate(),INTERVAL 7 day)"
    ) or die (mysql_error());
                    while(
    $row mysql_fetch_array($query))
                    {
                        
    $_xml .="\t<product>\r\n";
                        
    $_xml .="\t<title>" $row["name"] . "</title>\r\n";
                        
    $_xml .="\t<binding>" $row["binding"] . "</binding>\r\n";
                        
    $_xml .="\t<image>" $row["img"] . "</image>\r\n";
                        
    $_xml .="\t<release date>" $row["releasedate"] . "</release date>\r\n";
                        
    $_xml .="\t</product>\r\n";
                    }
                    
                    
    $query2 mysql_query("
                    SELECT cdID as id, cdName as name, cdBinding as binding, cdThumbIMG as img, cdReleaseDate as releasedate 
                    FROM tbl_cds 
                    WHERE cdReleaseDate >= curdate() and cdReleaseDate <= DATE_ADD(curdate(),INTERVAL 7 day)"
    ) or die (mysql_error());
                    while(
    $row mysql_fetch_array($query2))
                    {
                        
    $_xml .="\t<product>\r\n";
                        
    $_xml .="\t<title>" $row["name"] . "</title>\r\n";
                        
    $_xml .="\t<binding>" $row["binding"] . "</binding>\r\n";
                        
    $_xml .="\t<image>" $row["img"] . "</image>\r\n";
                        
    $_xml .="\t<release date>" $row["releasedate"] . "</release date>\r\n";
                        
    $_xml .="\t</product>\r\n";
                    }
                    
                    
    $query3 mysql_query("
                    SELECT gameID as id, gameName as name, gameBinding as binding, gameThumbIMG as img, gameReleaseDate as releasedate 
                    FROM tbl_games 
                    WHERE gameReleaseDate >= curdate() and gameReleaseDate <= DATE_ADD(curdate(),INTERVAL 7 day)"
    ) or die (mysql_error());
                    while(
    $row mysql_fetch_array($query3))
                    {
                        
    $_xml .="\t<product>\r\n";
                        
    $_xml .="\t<title>" $row["name"] . "</title>\r\n";
                        
    $_xml .="\t<binding>" $row["binding"] . "</binding>\r\n";
                        
    $_xml .="\t<image>" $row["img"] . "</image>\r\n";
                        
    $_xml .="\t<release date>" $row["releasedate"] . "</release date>\r\n";
                        
    $_xml .="\t</product>\r\n";
                    }

                    
    $query4 mysql_query("
                    SELECT bookID as id, bookName as name, bookBinding as binding, bookThumbIMG as img, bookReleaseDate as releasedate 
                    FROM tbl_books 
                    WHERE bookReleaseDate >= curdate() and bookReleaseDate <= DATE_ADD(curdate(),INTERVAL 7 day)"
    ) or die (mysql_error());
                    while(
    $row mysql_fetch_array($query4))
                    {
                        
    $_xml .="\t<product>\r\n";
                        
    $_xml .="\t<title>" $row["name"] . "</title>\r\n";
                        
    $_xml .="\t<binding>" $row["binding"] . "</binding>\r\n";
                        
    $_xml .="\t<image>" $row["img"] . "</image>\r\n";
                        
    $_xml .="\t<release date>" $row["releasedate"] . "</release date>\r\n";
                        
    $_xml .="\t</product>\r\n";
                    }
                    
                    
    $_xml .="\t</site>\r\n";
                    
    fwrite($file$_xml);

                     
    fclose($file);
                    
                     echo 
    "XML has been written.  <a href=\"index_latest_results.xml\">View the XML.</a>";


            
    ?>
    </body>
    </html>
    but when it creates the link to view the xml is says
    Code:
    XML Parsing Error: not well-formed
    Location: http://www.kernow-connect.com/index_latest_results.xml
    Line Number 6, Column 19:	<release date>2011-08-29</release date>
    -------------------------^
    not sure where im going wrong? any help is appreciated
    thanks
    Luke
    Last edited by LJackson; Aug 23, 2011, 01:47 PM.

  • #2
    <release date>

    This looks like a release tag with a date attribute, but the date attribute doesn't have a defined value. That breaks XML well-formedness rules. Similarly, your closing tag is incorrect (it shouldn't have the word "date" in it).

    These are valid:
    <release date="">...</release>
    <release_date>...</release_date>
    <release><date>Today</date>...</release>
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, ES-Membrane project (Github Pages site)
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

    Comment


    • #3
      nice one mate thank you!!!

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎