Sign in to follow this  
MichelBR

Xml Mysql Php

Recommended Posts

Good day!

 

I'm new to forum and I need a help!

 

I'm not able to create an XML to SQL below:

I have to generate a graph Stackedcolumn3D Model.

Please help me!

 


$strQueryCategories = "select distinct mes as mes from medicao order by equipe, mes asc";       
 // Query database
 $resultCategories = mysql_query($strQueryCategories) or die(mysql_error());
 // SQL query for factory output data
 $strQueryData = "select distinct mes, equipe, count(idpedido) as total from medicao group by equipe, mes order by equipe, mes asc";
 $resultData = mysql_query($strQueryData) or die(mysql_error());

 

 

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Welcome to FusionCharts Forum!smile.gif

Please follow the steps below:

 

1. First, include FusionCharts.js JavaScript class and FusionCharts.php to enable easy embedding of FusionCharts.

2. Then include DBConn.php, which contains connection parameters to connect to MySQL database.

3.Thereafter, generate the XML data document by iterating through each record and store it in a variable.

4. Finally, render the chart using renderChart() method and pass variable as data string.

 

For complete details, please visit: http://www.fusioncha...cs/?PHP_DB.html

Hope this helps.smile.gif

 

Share this post


Link to post
Share on other sites

Hi,

 

Welcome to FusionCharts Forum!smile.gif

Please follow the steps below:

 

1. First, include FusionCharts.js JavaScript class and FusionCharts.php to enable easy embedding of FusionCharts.

2. Then include DBConn.php, which contains connection parameters to connect to MySQL database.

3.Thereafter, generate the XML data document by iterating through each record and store it in a variable.

4. Finally, render the chart using renderChart() method and pass variable as data string.

 

For complete details, please visit: http://www.fusioncha...cs/?PHP_DB.html

Hope this helps.smile.gif

 

 

 

 

 

 

Angshu, thanks for the reply!

 

below is the complete code.

it even generates the graph, but he's messing up the values, the query is right, the problem buildDatasets this function, I can not see the error.

that you will be able to help me?

 

 

 


<?php
     //We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
     //functions to help us easily embed the charts and connect to a database.
     include("../Includes/FusionCharts.php");
     ?>
     <HTML>
        <HEAD>
       <TITLE>FusionCharts - Database Example</TITLE>
       <script LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
    </HEAD>
    <BODY>
    <CENTER>



<?php

$servidor = "localhost";
$usuario = "root";
$senha = "";
$banco = "plantap";


$con = mysql_connect($servidor, $usuario, $senha);
mysql_select_db ($banco);


 $strQueryCategories = "select distinct mes as mes from medicao order by equipe, mes asc";       
 // Query database
 $resultCategories = mysql_query($strQueryCategories) or die(mysql_error());
 // SQL query for factory output data
 $strQueryData = "select distinct mes, equipe, count(idpedido) as total from medicao group by equipe, mes order by equipe, mes asc";
 $resultData = mysql_query($strQueryData) or die(mysql_error());

 $strXML = "<chart legendPostion='1' caption='Factory Output report' subCaption='By Quantity' xAxisName='Factory' yAxisName='Units' showValues='0' formatNumberScale='0' rotateValues='1' animation='1'>";
 // Build category XML
$strXML .= buildCategories ($resultCategories, "mes");
 // Build datasets XML
$strXML .= buildDatasets ( $resultData, "total", "equipe");
 //Finally, close <chart> element
 $strXML .= "</chart>";
 //Create the chart - Pie 3D Chart with data from strXML
echo renderChart("../../FusionCharts/StackedColumn3D.swf", "", $strXML, "FactorySum", 1000, 550, false, true);
 // Free database resource
 mysql_free_result($resultCategories);
 mysql_free_result($resultData);
 mysql_close($con);

/***********************************************************************************************
* Function to build XML for categories
* @param        $result         Database resource
* @param        $labelField     Field name as String that contains value for chart category labels
* 
*       @return categories XML node 
*/
function buildCategories ( $result, $labelField )
{
 $strXML = "";
 if ($result) {
   $strXML = "<categories>";
   while($ors = mysql_fetch_array($result)) {
     $strXML .= "<category label='" . $ors[$labelField]. "'/>";
   }
   $strXML .= "</categories>";
 }
 return $strXML;
}

/***********************************************************************************************
* Function to build XML for datesets that would contain chart data
* @param        $result         Database resource. The data should come ordered by a control break 
field which would require to identify datasets and set its value to 
dataset's series name
* @param        $valueField     Field name as String that contains value for chart dataplots
* @param        $controlBreak   Field name as String that contains value for chart dataplots
* 
*       @return Dataset XML node 
*/
function buildDatasets ($result, $valueField, $controlBreak )
{
 $strXML = "";
 if ($result) {
   $controlBreakValue ="";
   while( $ors = mysql_fetch_array($result) ) {
     if( $controlBreakValue != $ors[$controlBreak] ) 
     {
       $controlBreakValue =  $ors[$controlBreak];
       $strXML .= ( $strXML =="" ? "" : "</dataset>") . ( "<dataset seriesName='" . $controlBreakValue . "'>" ) ;
     }
     $strXML .= "<set value='" . $ors[$valueField] . "'/>";
   }
   $strXML .= "</dataset>";
 }
 return $strXML;
}
?>




Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Thanks for your response.

 

builtDatasets() function is defined for our own samples and database.

 

In case you are using different data and database, you would need to create your own function.

 

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this