Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:36:23+00:00 2026-06-05T09:36:23+00:00

I’m working on outputting data from MySQL database in XML format, so I made

  • 0

I’m working on outputting data from MySQL database in XML format, so I made a php file that displays data from database in XML format on the page.

<?php
// Return all existing nid in array (Different types of form);
function nid(){
    $query = "SELECT w.nid 
                FROM webform w";
    $result = mysql_query($query);
    $table = array();
    while ($row = mysql_fetch_row($result)){
        $table[] = $row[0];
    }
    return $table;
}

// Return existing rows of corresponding nid
function sid($nid){
    $query = "SELECT ws.sid 
                FROM webform_submissions ws 
                WHERE ws.nid = $nid";
    $result = mysql_query($query);
    $table = array();
    while ($row = mysql_fetch_row($result)){
        $table[] = $row[0];
    }
    return $table;  
}
// Return corresponding components of nid;
function cid($nid){
    $query = "SELECT wc.form_key 
                FROM webform_component wc 
                WHERE wc.nid = $nid
                ORDER BY wc.cid ASC";
    $result = mysql_query($query);
    $table = array();
    while ($row = mysql_fetch_row($result)){
        $table[] = $row[0];
    }
    return $table;  
}

// Return values of fields corresponding to nid and sid
function data($nid, $sid){
    $query = "SELECT wsd.data 
                FROM webform_submitted_data wsd 
                WHERE wsd.nid = $nid AND wsd.sid = $sid
                ORDER BY wsd.sid ASC";
    $result = mysql_query($query);
    $table = array();
    while ($row = mysql_fetch_row($result)){
        $table[] = $row[0];
    }
    return $table;      
}
// Define Constants
DEFINE("DB_SERVER", "localhost");
DEFINE("DB_USER", "root");
DEFINE("DB_PASS", "");
DEFINE("DB_NAME", "drupal7");

//Establish Connection
mysql_connect(DB_SERVER, DB_USER, DB_PASS)
    or die("Unable to connect to MySQL");

//Select Database
mysql_select_db(DB_NAME)
    or die("Could not connect to the database");

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

foreach (nid() as $nid){
    $xml_output .= "<form fid=\"$nid\">\n";
    foreach (sid($nid) as $sid){
        $xml_output .= "<row rid=\"$sid\">\n";
        for ($i = 0; $i < count(cid($nid)); $i++){
            $tag_array = cid($nid);
            $value_array = data($nid, $sid);
            $tag_row = $tag_array[$i];
            $value_row = $value_array[$i];
            $xml_output .= "<$tag_row>\n";
            $xml_output .= "$value_row\n";
            $xml_output .= "</$tag_row>\n";
        }
        $xml_output .= "</row>\n";
    }
    $xml_output .= "</form>\n";
}
$xml_output .= "</schema>";

header("Content-type: text/xml");
echo $xml_output;
mysql_close();

?>

But I can’t see to find a way to access the XML data or download it as XML file.

Here’s how the output looks like when I run it.
enter image description here

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:36:24+00:00Added an answer on June 5, 2026 at 9:36 am

    Don’t use strings to build your xml data. You should be using something like SimpleXMLElement

    See How to generate XML file dynamically using PHP?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.