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 3 of 3

Thread: PHP and XML

  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP and XML

    Hello All,
    wondering if you could help me? I am using PHP to output my database results in XML. At the moment PHP outputs the XML but its still .php is there a way that PHP can output my results in xml in a seperate document that will be .xml..is this even achieveable?

    here is my code;

    Code:
    <?php 
    
    $link = mysql_connect("localhost","root",""); 
    mysql_select_db("fashion"); 
    
    $query = "SELECT ilink,image_name,description FROM gallery"; 
    
    $results = mysql_query($query); 
    
    echo "<?xml version=\"1.0\"?>\n";  
    echo "<photos path=\"images/\">\n"; 
    while($line = mysql_fetch_array($results)) { 
        echo "<photo name=\"".$line['image_name']."\" url=\"".$line['ilink']."\">".$line['description']."</photo>\n";
    } 
    echo "</photos>\n"; 
    mysql_close($link); 
    ?>
    Thanks in advance

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Instead of echoing to the screen, open a file called "photos.xml" and write to it.
    You also need to form the XML properly, with proper XML tags.
    A lot of information about PHP creating XML files using Google.

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Add
    PHP Code:
    header ("content-type: text/xml"); 
    before any output (the top of the script is preferable). That should do it. It is possible to rewrite an xml document to a php script and do this, but I believe it should work
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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