DangerM0use Posted December 29, 2007 Share Posted December 29, 2007 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 https://forums.phpfreaks.com/topic/83601-php-and-xml/ Share on other sites More sharing options...
Daniel0 Posted December 29, 2007 Share Posted December 29, 2007 for($i=0;$i<$num;$i++){ Where is $num set? Link to comment https://forums.phpfreaks.com/topic/83601-php-and-xml/#findComment-425558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.