efonseca

Help on more than 1 set from DB and PHP

Recommended Posts

hi

 

i'm a newbiee in XML and PHP :)

 

how can i get more than one set from a DB connection

 

 

 

from the example below how can i get a chart with Total and Avaliados.. or more if needed

 

 

 

$link = connectToDB();

 

$useUTFQuery = "SET NAMES 'utf8'";

 

$utfQueryResult = mysql_query($useUTFQuery);

 

$strQuery = "SELECT Dep, Count(*) AS Total FROM, Count(DataAval) AS Avaliados DAI_main GROUP BY Dep";

 

$result = mysql_query($strQuery) or die(mysql_error());

 

$strXML = "graph decimalPrecision='0' rotateNames='0' xaxisname='Departamentos' yaxisname='Colaboradores' showBorder='0' showPercentageValues='0' showPercentageInLabel='0' >";

 

 

 

if ($result) {

 

while($ors = mysql_fetch_array($result)) {

 

$strXML .= "set name='" . $ors['Dep']."' value='" . $ors['Total'] . "' color='FDC12E'/>";

 

}

 

}

 

mysql_close($link);

 

$strXML .= "/graph>";

 

echo renderChart("Charts/FCF_Column3D.swf", "", $strXML, "ChartId", 650, 450, false, false);

 

?>

 

 

 

Note: < is taken off so all code can be see

Edited by Guest

Share this post


Link to post
Share on other sites

i've triyed like this but i get a invalid xml data.

 

 

 

 

link = connectToDB();

 

strXML = "graph decimalPrecision='0' rotateNames='0' xaxisname='Departamentos' yaxisname='Colaboradores' showBorder='0' showPercentageValues='0' showPercentageInLabel='0' >";

 

$strCat = "categories>";

 

$strTotDS = "dataset seriesname='Total'>";

 

$strAvalDS = "dataset seriesname='Avaliados'>";

 

$strQuery = "SELECT Dep, Count(*) AS Total, Count(DataAval) AS Avaliados FROM DAI_main GROUP BY Dep";

 

$result = mysql_query($strQuery) or die(mysql_error());

 

if ($result) {

 

while($ors = mysql_fetch_array($result)) {

 

strCat .= "category label='" . $ors['Dep'] . "'/>";

 

strTotDS .= "set value='" . $ors['Total'] . "' />";

 

strAvalDS .= "set value='" . $ors['Avaliados'] . "'/>";

 

}

 

}

 

mysql_close($link);

 

strCat .= "/categories>";

 

strTotDS .= "/dataset>";

 

strAvalDS .= "/dataset>";

 

strXML = $strCat . $strTotDS . $strAvalDS;

 

strXML .= "/graph>";

 

echo renderChart("/chart/Charts/FCF_Column3D.swf", "", $strXML, "ChartId", 650, 450, false, false);

 

 

 

Note: < is taken off so all code can be seen

 

Edited by Guest

Share this post


Link to post
Share on other sites

chart_ChartId.setDataXML("

categories>

category label='AAD'/> category label='CA?'/> category label='CGT'/> category label='CMP'/>

category label='CNT'/> category label='COM'/> category label='DAF'/> category label='DCE'/>

category label='DGE'/> category label='DID'/> category label='DMN'/> category label='GES'/>

category label='INF'/> category label='LAB'/> category label='OPA'/> category label='QLA'/>

category label='RH'/> category label='SSG'/> category label='TSR'/>

/categories>

dataset seriesname='Total'>

set value='1' /> set value='2' /> set value='2' /> set value='2' /> set value='4' /> set value='45' /> set value='1' /> set value='3' /> set value='1' /> set value='4' /> set value='29' /> set value='1' /> set value='2' /> set value='9' /> set value='29' /> set value='2' /> set value='3' /> set value='2' /> set value='2' /> 

/dataset>

dataset seriesname='Avaliados'>

set value='0'/> set value='0'/> set value='0'/> set value='0'/> set value='0'/> set value='8'/> set value='1'/> set value='0'/> set value='0'/> set value='4'/> set value='0'/> set value='0'/> set value='1'/> set value='0'/> set value='0'/> set value='0'/> set value='0'/> set value='2'/> set value='0'/> 

/dataset>

/graph>")



chart_ChartId.render("ChartIdDiv");





Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

1. Your XML should start with <graph> element, that is missing.
 
2. We have found that your XML contains a ? (Question mark) character, due to this you are getting the error, please remember XML should not contain any special character(s).
Also please make sure that, if your Database contains UTF8 character then you are also getting the UTF8 chatacter in your HTML page too, and this UTF character is converted into a ? character, because you might have not saved that HTML/PHP file as UTF8 enabled.
So, in order to work with that, please save your HTML/PHP file with UTF8 support.
 
Also please check the code below:
 
link = connectToDB();

$strXML = "<graph decimalPrecision='0' rotateNames='0' xaxisname='Departamentos' yaxisname='Colaboradores' showBorder='0' showPercentageValues='0' showPercentageInLabel='0' >";

$strCat = "categories>";

$strTotDS = "dataset seriesname='Total'>";

$strAvalDS = "dataset seriesname='Avaliados'>";

$strQuery = "SELECT Dep, Count(*) AS Total, Count(DataAval) AS Avaliados FROM DAI_main GROUP BY Dep";

$result = mysql_query($strQuery) or die(mysql_error());

if ($result) {

while($ors = mysql_fetch_array($result)) {

strCat .= "<category label='" . $ors['Dep'] . "'/>";

strTotDS .= "<set value='" . $ors['Total'] . "' />";

strAvalDS .= "<set value='" . $ors['Avaliados'] . "'/>";

}

}

mysql_close($link);

$strCat .= "</categories>";

$strTotDS .= "</dataset>";

$strAvalDS .= "</dataset>";

$strXML .= $strCat . $strTotDS . $strAvalDS; // String concatenation "." was missing.

$strXML .= "</graph>";

echo renderChart("/chart/Charts/FCF_Column3D.swf", "", $strXML, "ChartId", 650, 450, false, false);

 

The XML:
 
<graph decimalPrecision='0' rotateNames='0' xaxisname='Departamentos' yaxisname='Colaboradores' showBorder='0' showPercentageValues='0' showPercentageInLabel='0' > 
<categories>

  <category label='AAD'/>

  <category label='CA?'/>

  <category label='CGT'/>

  <category label='CMP'/>

  <category label='CNT'/>

  <category label='COM'/>

  <category label='DAF'/>

  <category label='DCE'/>

  <category label='DGE'/>

  <category label='DID'/>

  <category label='DMN'/>

  <category label='GES'/>

  <category label='INF'/>

  <category label='LAB'/>

  <category label='OPA'/>

  <category label='QLA'/>

  <category label='RH'/>

  <category label='SSG'/>

  <category label='TSR'/>

</categories>

<dataset seriesname='Total'>

  <set value='1' />

  <set value='2' />

  <set value='2' />

  <set value='2' />

  <set value='4' />

  <set value='45' />

  <set value='1' />

  <set value='3' />

  <set value='1' />

  <set value='4' />

  <set value='29' />

  <set value='1' />

  <set value='2' />

  <set value='9' />

  <set value='29' />

  <set value='2' />

  <set value='3' />

  <set value='2' />

  <set value='2' />

</dataset>

<dataset seriesname='Avaliados'>

  <set value='0'/>

  <set value='0'/>

  <set value='0'/>

  <set value='0'/>

  <set value='0'/>

  <set value='8'/>

  <set value='1'/>

  <set value='0'/>

  <set value='0'/>

  <set value='4'/>

  <set value='0'/>

  <set value='0'/>

  <set value='1'/>

  <set value='0'/>

  <set value='0'/>

  <set value='0'/>

  <set value='0'/>

  <set value='2'/>

  <set value='0'/>

</dataset>

</graph>

Edited by Guest

Share this post


Link to post
Share on other sites

Hi

 

After de correction that you propose i get the "No data to display"

 

 

 

the XML looks as before..

 

 

 

Best Regards

 

Eduardo

Edited by Guest

Share this post


Link to post
Share on other sites

:D

 

offcourse it wouldnt work. i was trying to see a multi on a single...

 

 

 

i'm so dummmm

 

 

 

tks for all your help..

 

 

 

all tested all working going to upgrade.. tks

 

 

 

regards

 

Eduardo

Edited by Guest

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