Reputation: 93
I want make some chart using xml file and call the chart using javascript, however I got a problem in Data.php(that contain php and xml to build the chart). This is my code :
<?php require_once('../../Connections/edb.php'); ?>
<?php
mysql_select_db($db, $edb) or die(mysql_error());
$parlimen[] = "Segamat";
$parlimen[] = "Sekijang";
$parlimen[] = "Labis";
foreach ($parlimen as $p){
$count = mysql_query("SELECT COUNT(*) FROM tbl_ahli WHERE parlimen = '".$p."' AND status='Perwakilan'");
$result = mysql_fetch_assoc($count) or die(mysql_error());
//print $result['COUNT(*)'];
//the result some thing like
//for three loop 100,
//if I print like this :
//print $p." = ".$result100['COUNT(*)']."<br/>" or die(mysql_error()) ;
//the result will be like this
// Segamat = 1
// Sekijang = 0
// Labis = 0
}
?>
This is my PHP Code who contains my XML Code:
<?php
header("Content-type: text/xml");
echo "<chart caption='Weekly Sales Summary for two Products' xAxisName='Weeks' yAxisName='Amount' yAxisMinValue='0' yAxisMaxValue='500' adjustDiv='0' numDivLines='9'> ";
echo "<categories>";
echo "<category Label=\"Segamat\"/>";
echo "<category Label=\"Sekijang\"/>";
echo "<category Label=\"Labis\"/>";
echo "</categories>";
echo "<dataset seriesName=\"Product A\">";
echo "<set value='$result' /> ";
echo "<set value='$result' /> ";
echo "<set value='$result' /> ";
echo "</dataset>";
echo "</chart>";
?>
I make these two code with the same file name Data.php, I make xml in php. I have problem to submit result from the query into xml
This is my javascript to call the Data.php and chart
<body>
<div id="chartContainer">FusionCharts XT will load here!</div>
<script type="text/javascript"><!--
var myChart = new FusionCharts( "MSColumn3D.swf",
"myChartId", "400", "300", "0" );
myChart.setXMLUrl("Data.php");
myChart.render("chartContainer");
// -->
</script>
Upvotes: 0
Views: 123
Reputation: 93
The answer is :
<?php
header("Content-type: text/xml");
echo "<chart caption='Bilangan Ahli Mengikut Parlimen' xAxisName='Parlimen' yAxisName='Jumlah(Orang)' yAxisMinValue='0' yAxisMaxValue='500' adjustDiv='0' numDivLines='9' canvasbgcolor='#FFFFFF' canvasbasecolor='#CCCCCC' showcanvasbg='1' palettecolors='#008ee4,#6baa01,#f8bd19,#e44a00,#33bdda' divlinecolor='#CCCCCC' divlinealpha='70' useroundedges='1'> ";
foreach ($parlimen as $p){
$count = mysql_query("SELECT COUNT(*) FROM tbl_ahli WHERE parlimen = '".$p."' AND status='Perwakilan'");
$result = mysql_fetch_assoc($count) or die(mysql_error());
echo "<set label=\"".$p."\" value=\"".$result['COUNT(*)']."\" />";
}
echo "</chart>";
Upvotes: 1