tekrscom Posted June 1, 2007 Share Posted June 1, 2007 Could someone please give me a bit of help on how to create this XML file? I have these two queries that give me the values for my two variables, $completed and $not_completed. <? include_once "connection.php"; $first_query = mysql_query("SELECT gold_id FROM logs WHERE task = 'XALM Installation - Integration'"); $total = mysql_num_rows($first_query); $second_query = mysql_query("SELECT log_id FROM logs WHERE task = 'XALM Installation - Integration' && task_completed = '0'"); $not_completed = mysql_num_rows($second_query); $completed = $total - $not_completed; ?> I need to insert those two into an XML file that is called upon by a page that has the graph. <?xml version="1.0" encoding="utf-8"?> <graph> <general_settings bg_color="FFFFFF" /> <header text="Jobs for Expansion Installation - Integration" font="Verdana" color="000000" size="18" /> <subheader text="" font="Verdana" color="000000" size="15" /> <legend font="Verdana" font_color="000000" font_size="11" bgcolor="FFFFFF" alternate_bg_color="FFF9E1" border_color="BFBFBF" /> <legend_popup font="Verdana" bgcolor="FFFFE3" font_size="10" /> <pie_chart radius="100" height="35" angle_slope="45" alpha_sides="60" alpha_lines="20" /> <data name="Completed" value="<? echo $not_completed; ?>" color="FF0000" /> <data name="Not Completed" value="<? echo $completed; ?>" color="333333" /> </graph> I know that you can't put the PHP in the code like that, I just put them there for reference. So I need to create this dynamic XML page and call it the same thing everytime so that it can be called by the flash graph, like sites_completed_graph.xml Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/ Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 you need to look at www.php.net/header set the content type to be the xml type (maybe text/xml) and just print it to the screen. <?php include_once "connection.php"; $first_query = mysql_query("SELECT gold_id FROM logs WHERE task = 'XALM Installation - Integration'"); $total = mysql_num_rows($first_query); $second_query = mysql_query("SELECT log_id FROM logs WHERE task = 'XALM Installation - Integration' && task_completed = '0'"); $not_completed = mysql_num_rows($second_query); $completed = $total - $not_completed; header("Content-type:text/xml"); ?> <?xml version="1.0" encoding="utf-8"?> <graph> <general_settings bg_color="FFFFFF" /> <header text="Jobs for Expansion Installation - Integration" font="Verdana" color="000000" size="18" /> <subheader text="" font="Verdana" color="000000" size="15" /> <legend font="Verdana" font_color="000000" font_size="11" bgcolor="FFFFFF" alternate_bg_color="FFF9E1" border_color="BFBFBF" /> <legend_popup font="Verdana" bgcolor="FFFFE3" font_size="10" /> <pie_chart radius="100" height="35" angle_slope="45" alpha_sides="60" alpha_lines="20" /> <data name="Completed" value="<?php echo $not_completed; ?>" color="FF0000" /> <data name="Not Completed" value="<?php echo $completed; ?>" color="333333" /> </graph> No harm in that. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-266536 Share on other sites More sharing options...
tekrscom Posted June 2, 2007 Author Share Posted June 2, 2007 I don't understand how that is going to work... The page with the graph needs to call an xml file... Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-266969 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 Too narrow minded my friend. Any file can technically be an "html" file as long as the receiveing site sees the xml header. <?php include_once "connection.php"; $first_query = mysql_query("SELECT gold_id FROM logs WHERE task = 'XALM Installation - Integration'"); $total = mysql_num_rows($first_query); $second_query = mysql_query("SELECT log_id FROM logs WHERE task = 'XALM Installation - Integration' && task_completed = '0'"); $not_completed = mysql_num_rows($second_query); $completed = $total - $not_completed; header("Content-type:text/xml"); header('Content-Disposition: inline; filename=graph.xml'); // there that will put it into a good name. ?> <?xml version="1.0" encoding="utf-8"?> <graph> <general_settings bg_color="FFFFFF" /> <header text="Jobs for Expansion Installation - Integration" font="Verdana" color="000000" size="18" /> <subheader text="" font="Verdana" color="000000" size="15" /> <legend font="Verdana" font_color="000000" font_size="11" bgcolor="FFFFFF" alternate_bg_color="FFF9E1" border_color="BFBFBF" /> <legend_popup font="Verdana" bgcolor="FFFFE3" font_size="10" /> <pie_chart radius="100" height="35" angle_slope="45" alpha_sides="60" alpha_lines="20" /> <data name="Completed" value="<?php echo $not_completed; ?>" color="FF0000" /> <data name="Not Completed" value="<?php echo $completed; ?>" color="333333" /> </graph> try it out and see what happens, the script still needs to be named script.php to work. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-266985 Share on other sites More sharing options...
tekrscom Posted June 2, 2007 Author Share Posted June 2, 2007 Ok, I took that code and named the page script.php and then changed the chart calling code to call graph.xml... it didn't work ... When I looked in the directory, there wasn't a file called graph.xml... So I thought that maybe I had to call the script.php to run to create the graph.xml page before calling the graph.xml page, so I did an include_once = "script.php"; before the graph software... it still didn't create the file... Hmmmm, I'm lost. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-267030 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 Its not going to create the file, if you want it to create a file, than you need to use www.php.net/fopen www.php.net/fwrite www.php.net/fclose Using that code above if you goto script.php it is viewed as an xml file. Alright I will give you an example, <?php header("Content-type:text/xml"); $not_completed = "test"; $completed = "test2"; echo '<?xml version="1.0" encoding="utf-8"?> <graph> <general_settings bg_color="FFFFFF" /> <header text="Jobs for Expansion Installation - Integration" font="Verdana" color="000000" size="18" /> <subheader text="" font="Verdana" color="000000" size="15" /> <legend font="Verdana" font_color="000000" font_size="11" bgcolor="FFFFFF" alternate_bg_color="FFF9E1" border_color="BFBFBF" /> <legend_popup font="Verdana" bgcolor="FFFFE3" font_size="10" /> <pie_chart radius="100" height="35" angle_slope="45" alpha_sides="60" alpha_lines="20" /> <data name="Completed" value="' . $not_completed . '" color="FF0000" /> <data name="Not Completed" value="'.$completed.'" color="333333" /> </graph>'; ?> You can see the end results here: www.aeonity.com/test/xmltest.php The browser sees it as an xml file due to the header call. If you want to write it to a file, than you want to remove the header part and use the functions above to do that. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-267048 Share on other sites More sharing options...
tekrscom Posted June 2, 2007 Author Share Posted June 2, 2007 Using that code above if you goto script.php it is viewed as an xml file. When I go to the script.php page it doesn't show anything at all... Not like your example. The browser sees it as an xml file due to the header call. I tried calling script.php, thinking that it would see it as an xml page as you said, but probably something related to why I can't view it as an xml file when going directly to it, has something to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-267058 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 http://www.aeonity.com/test/xmltest.phps there is the source. Maybe add error_reporting(E_ALL); to the top to make sure the errors are showing up if any. Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-267070 Share on other sites More sharing options...
tekrscom Posted June 2, 2007 Author Share Posted June 2, 2007 I got it, THANK YOU very much for your patience and help... Quote Link to comment https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/#findComment-267129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.