Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

XML PHP MYSQL- Writing to a xml file

  • 07-03-2008 6: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