Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XML PHP MYSQL- Writing to a xml file

  • 07-03-2008 07:18PM
    #1
    Registered Users, Registered Users 2 Posts: 45


    I have code written to generate xml data in PHP from my MySQL database. I can display this in my browser using "echo" but what I really want is to write this xml data to a seperate xml file so that I can have flash use it.

    Here is my code:

    [PHP]
    <?php require_once('Connections/PhotoABC.php'); ?>
    <?php
    if (!isset($_SESSION)) {
    session_start();
    }

    $sqluserid = "SELECT `user_id` FROM `user` WHERE `username` = '".$_SESSION."'";
    $useridqueryresult = mysql_query($sqluserid)
    or die (mysql_error());
    if (mysql_num_rows($useridqueryresult) > 0) {
    $row=mysql_fetch_assoc($useridqueryresult);
    $userid=$row;
    }

    $sqlimagename = "SELECT `image_name` FROM `gallery` WHERE `user_id` = '$userid'";
    $imagenamequeryresult = mysql_query($sqlimagename)
    or die (mysql_error());

    $xml_output = "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<images>\n";

    for($x = 0 ; $x < mysql_num_rows($imagenamequeryresult) ; $x++){
    $row = mysql_fetch_assoc($imagenamequeryresult);
    $xml_output .= "\t<image>\n";
    xml_output .= "\t\t<image>" . $row . "</image>\n";
    $xml_output .= "\t</image>\n";
    }

    $xml_output .= "</images>";

    echo $xml_output;

    ?>[/PHP]

    I would like to write this xml data to a new xml file called "images.xml" and to save it to this directory
    "C:\htdocs\PhotoABC\upload_test\Jordan"

    Any help would be great :)


Comments

  • Registered Users, Registered Users 2 Posts: 45 Jordan79


    I have this working now.
    Here is the code I used:


    [PHP]$filenamepath .= "images.xml";

    $fp = fopen($filenamepath,'w');

    $write = fwrite($fp,$xml_output);

    echo $xml_output;[/PHP]


Advertisement