Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/53907-solved-help-with-php-creating-xml-file/
Share on other sites

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.

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.

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. :(

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.

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.

 

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.