Jump to content

PHP and XML


DangerM0use

Recommended Posts

Hi all.

 

I'm struggling with something and I hope that someone can help. Basically, what I need to do is create a page, that when loaded runs a PHP script. The result of this PHP script basically joins two tables together. I have done that and it works OK.

 

But, what I need to do after that is display this data in an XML document. I have this partly created, but, no data is being displayed. I believe this is because I have no elements declared. The fieldnames from the tables are to be used to name the containing in the XML document.

 

This is the code that I have in the PHP page;

 

# opens the file xyz.xml for writing
$handle=fopen("xyz.xml","w");

# writes the header to the xml file
fwrite($handle,'<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>');

# puts a space in the file
fwrite($handle,"\n");

/*Remove these quote marks once CSS is created
# writes the stylesheet code to the xml file
fwrite($handle,'<?xml-stylesheet type="text/xsl" href="xyz.xsl"?>');
*/

# puts a space in the the next line
fwrite($handle,"\n");

# opens the tag 'data collection' that is used to signify the beginning of the data collection from the SQl tables that
# will be put in the xml file and uses the XSL stylesheet to view it in a browser correctly
fwrite($handle,"<getdata>");

# the SQL query to get the data from the database
while ($newrow=mysql_fetch_row($result)) {

# writes the opening tag 'data' that shows the beginning of the data got from the sql tables
fwrite ($handle,"<data>\n");

# counts number of lines in the data
for($i=0;$i<$num;$i++){

# writes the fieldnames
fwrite ($handle,"<$fieldnames[$i]>$newrow[$i]</$fieldnames[$i]>");
}

# counts the fieldnames
for($i=$num;$i<count($fieldnames);$i++){

# writes the fieldnames
fwrite ($handle,"<$fieldnames[$i]>$newrow[$i]</$fieldnames[$i]>");
}

# writes the 'data' closing tags
fwrite ($handle,"</data>\n");
}

# writes the closing 'data collection'
fwrite($handle,"</getdata>");

 

From this when I run the .php page and then go to the xml page I get the following;

 

<getdata>

<data> </data>

<data> </data>

<data> </data>

etc

</getdata>

 

So, where am I going wrong. Where do I put the tables fieldnames in so that it links to the information that is brought from the earlier php query?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.