View unanswered posts | View active topics It is currently Tue Apr 16, 2024 11:42 am



Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
bar graph empty data from mysql 
Author Message
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: bar graph empty data from mysql
There a too many design problem with your code, the HTML part must look like this :

stat.php
Code:
<html>
<head><title>test</title></head>
<body>
<?php
require_once "config.php";

$age1  = $_POST["age1"];
$admin = $_POST['admin'];
foreach($admin as $categ)
  {
   $key=rand();

   echo "$categ <br/>";
   $sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";
   $result = mysql_query($sql) or die(mysql_error());
   $Nombre="";
   $annee="";

   echo "<table border='1'>";
   echo " <tr>";
   echo "  <th>Nombre</th>";
   echo "  <th>annee</th>";
   echo "  <th>CIMO</th>";
   echo " </tr>";

   while($row = mysql_fetch_assoc($result))
    {
     echo " <tr>";
     echo "  <td>" . $row['Nombre'] . "</td>";
     echo "  <td>" . $row['annee'] . "</td>";
     echo "  <td>" . $row['CIMO'] . "</td>";
     echo " </tr>";
    }
   echo "</table>";
   echo "<br/><br/>";
  }
mysql_close($con)
?>
<IMG SRC='mypChartScript.php?age1=<?php echo $age1; ?>&admin=<?php echo $admin; ?>'>
</body>
</html>


giving the two parameters called age1 and admin to the chart script that will also connect on its own to the db and create the datasets.

Some questions :

  • What is admin1, how can you pass an array as a POST variable?!
  • It looks to me that you're entering the $Nombre=""; line many time, this means that your dataset is reseted each time.


Thu Sep 01, 2011 1:13 pm
Profile WWW
Regular pChart user
Regular pChart user

Joined: Thu Sep 01, 2011 8:47 am
Posts: 11
Post Re: bar graph empty data from mysql
Thanks for your help :P ,

To answer to your question, here's the mechanical :

i have a form page where there are checkboxes :

form page :
Code:
...
<?php
<form action="stat.php" method="POST">
...
echo '<td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="admin[]" value="'.$cimo3.'" /></td>';?>
<td><?php echo $cimo3 ?></td>
<td><?php echo $fnomen?></td>
...
</form>


for each checkbox checked I applied the query in order to calculate several content and show the content into a table. My goal is to put a graphic for each content table contained in the foreach loop.

I applied what u adviced to me.

But there is something that I don't understand, where i have to put the include to mypChartScript.php in my html ?

I guess in the foreach loop in order to get a different graphic for each category calculated:

Code:
...
while($row = mysql_fetch_assoc($result))
    {
     echo " <tr>";
     echo "  <td>" . $row['Nombre'] . "</td>";
     echo "  <td>" . $row['annee'] . "</td>";
     echo "  <td>" . $row['LesioCIMO'] . "</td>";
     echo " </tr>";
    }
   echo "</table>";
   echo "<br/><br/>";
include "mypChartScript.php";
  }


2 problems :

1°) I have this error : Fatal error: Cannot redeclare class pData in c:\...\pChart\pData.class on line 49
2°) if i remove include "mypChartScript.php"; from the foreach loop and put it outside, I have just one .png generated on my hard disk drive but it doesn"t appear in my WEB page moreover if I have 2 tables i should get 2 graphics and i have only one :cry:

Do you know how can I do ?

Thanks a lot for your help.


Thu Sep 01, 2011 2:03 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: bar graph empty data from mysql
Got it!

Do you want to create one chart by selected checkbox or draw everything on the same chart (then the number of series will be the same than the number of actived checkboxes).

-You don't need to include the second script, this one is standalone. The <IMG tag will trigger its execution.


Thu Sep 01, 2011 2:11 pm
Profile WWW
Regular pChart user
Regular pChart user

Joined: Thu Sep 01, 2011 8:47 am
Posts: 11
Post Re: bar graph empty data from mysql
yeah :D , I actually want to create one chart by selected checkbox.

More precisely, items which can be selected in the checkbox are CIMO which appear in my query as a variable :

$sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";

When you say :
Quote:
You don't need to include the second script, this one is standalone. The <IMG tag will trigger its execution.


I tried to do that, but I have no picture file created and no pic shows in the webpage :( .


Thu Sep 01, 2011 2:26 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: bar graph empty data from mysql
You can try something like this :

stat.php
Code:
<html>
<head><title>test</title></head>
<body>
<?php
require_once "config.php";

$age1  = $_POST["age1"];
$admin = $_POST['admin'];
foreach($admin as $categ)
  {
   $key=rand();

   echo "$categ <br/>";
   $sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";
   $result = mysql_query($sql) or die(mysql_error());
   $Nombre="";
   $annee="";

   echo "<table border='1'>";
   echo " <tr>";
   echo "  <th>Nombre</th>";
   echo "  <th>annee</th>";
   echo "  <th>CIMO</th>";
   echo " </tr>";

   while($row = mysql_fetch_assoc($result))
    {
     echo " <tr>";
     echo "  <td>" . $row['Nombre'] . "</td>";
     echo "  <td>" . $row['annee'] . "</td>";
     echo "  <td>" . $row['CIMO'] . "</td>";
     echo " </tr>";
    }
   echo "</table>";
   echo "<br/><br/>";

   echo "<img src='mypChartScript.php?age1=<?php echo $age1; ?>&categ=<?php echo $categ; ?>' alt='' />
  }
mysql_close($con)
?>
</body>
</html>


mypChartScript.php
Code:
<?php
require_once "config.php";
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");

$age1  = $_GET["age1"];
$categ = $_GET["categ"];

$sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";
$result = mysql_query($sql) or die(mysql_error());
$Nombre=""; $annee="";
while($rowz = mysql_fetch_array($result))
  {
   $Nombre[] = $rowz['Nombre'];
   $annee[]  = $rowz['annee'];
  }
mysql_close($con)

$myData = new pData();
$myData->addPoints($Nombre,"Nombre");
$myData->addPoints($annee,"Annee");
$myData->setAbscissa("Annee");

$myPicture = new pImage(700,230,$myData);

$myPicture->setGraphArea(60,40,670,190);
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawScale();
$myPicture->drawBarChart();

$myPicture->stroke;
?>


Thu Sep 01, 2011 3:17 pm
Profile WWW
Regular pChart user
Regular pChart user

Joined: Thu Sep 01, 2011 8:47 am
Posts: 11
Post Re: bar graph empty data from mysql
Hi jean-damien,

thanks a lot for the time that you past on my problem. I tried ur code but i don't have any chart drew on my WEBPAGE :cry:

Do you know why?

Thanks again.


Thu Sep 01, 2011 5:08 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: bar graph empty data from mysql
It can be many things as I don't know the file & class structure on your server. Is your page on an internet web server? If yes, can you give me the URL? if not you may need to put directly the URL (contained in the SRC element of the <IMG tags) of the pictures in your browser so you'll see the server PHP error message.


Thu Sep 01, 2011 7:49 pm
Profile WWW
Regular pChart user
Regular pChart user

Joined: Thu Sep 01, 2011 8:47 am
Posts: 11
Post Re: bar graph empty data from mysql
hello jean-damien,

I'm working at the present time on the localhost environnement by using easyphp. I took a look the directly at the URL which contained in the SRC element of the <IMG> tags of the pictures in my browser.

It missed the () at "stroke" at the line $myPicture->stroke(); at the end.

I have now a chart for each $categ but the chart is an horizontal line. It seems not drawing the bar chart :(

If I put the the echo '<img...' tag outside the foreach loop, i have a bar chart but only for one not for the each $categ.

stat.php
Code:
<html>
<head><title>test</title></head>
<body>
<?php
require_once "config.php";

$age1  = $_POST["age1"];
$admin = $_POST['admin'];

   
foreach($admin as $categ)
  {
   $key=rand();
   
   echo "$categ <br/>";
   $sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";
   $result = mysql_query($sql) or die(mysql_error());
   

   echo "<table border='1'>";
   echo " <tr>";
   echo "  <th>Nombre</th>";
   echo "  <th>annee</th>";
   echo "  <th>CIMO</th>";
   echo " </tr>";

   while($row = mysql_fetch_assoc($result))
    {
     echo " <tr>";
     echo "  <td>" . $row['Nombre'] . "</td>";
     echo "  <td>" . $row['annee'] . "</td>";
     echo "  <td>" . $row['CIMO'] . "</td>";
     echo " </tr>";
    }
   echo "</table>";
   echo "<br/><br/>";
   
//The bar chart is not drawn, i have an horizontal line
   echo "<IMG SRC='mypChartScript.php?age1=$age1&categ=$categ;'>";
  }
 
mysql_close($con);
?>
<!--here i have a bar chart but only one $categ not for all :(-->
<IMG SRC='mypChartScript2.php?age1=<?php echo $age1; ?>&categ=<?php echo $categ; ?>'>
</body>
</html>


mypChartScript.php
Code:
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");

require_once "config.php";

$age1  = $_GET["age1"];
$categ = $_GET["categ"];

$sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc";
$result = mysql_query($sql) or die(mysql_error());
$Nombre=""; $annee="";
while($rowz = mysql_fetch_array($result))
  {
   $Nombre[] = $rowz['Nombre'];
   $annee[]  = $rowz['annee'];
  }
mysql_close($con);

$myData = new pData();
$myData->addPoints($Nombre,"Nombre");
$myData->addPoints($annee,"Annee");
$myData->setAbscissa("Annee");

$myPicture = new pImage(700,230,$myData);

$myPicture->setGraphArea(60,40,670,190);
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawScale();
$myPicture->drawBarChart();

$myPicture->stroke();
?>


Fri Sep 02, 2011 7:28 am
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: bar graph empty data from mysql
Just put back the code I've written :

Code:
echo "<img src='mypChartScript.php?age1=<?php echo $age1; ?>&categ=<?php echo $categ; ?>' alt='' />

instead of yours :
Code:
echo "<IMG SRC='mypChartScript.php?age1=$age1&categ=$categ;'>";


There is a typo in your code the ";" is appended to the $categ variable.

JD.


Fri Sep 02, 2011 7:37 am
Profile WWW
Regular pChart user
Regular pChart user

Joined: Thu Sep 01, 2011 8:47 am
Posts: 11
Post Re: bar graph empty data from mysql
wow :D :D , yeah it works now. I've bar chart for each element.

Thank you very much JD for help and time that you past on my problem.

A+
Jarod.


Fri Sep 02, 2011 8:04 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron