0

Hello.

I am trying to connect my MYSQL Database to my JpGraph but it is not working.
Any help is appriciated. Here is my conde.

 <?php
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph.php");   
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_bar.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_line.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_pie.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_pie3d.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/db.inc");

$host = "localhost";
$username = "root";
$password = "";
$database = "test";


$connection=mysql_connect ($host, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$sqlTotal = "SELECT count(*) AS Number FROM students"; 


$total = mysql_query($sqlTotal);


while($resultTotal = mysql_fetch_array($total))
{
    $totalValue = $resultTotal['Number'];
}


$data = array($totalValue);

$graph = new PieGraph(410, 310,"auto");
$graph->SetShadow();
$graph->title->Set("Wireless Encryption Schemes in Dublin, Ireland");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$p1 = new PiePlot3D($data);
$p1->SetSize(.3);
$p1->SetCenter(0.45);
$p1->SetStartAngle(300); 
$p1->SetAngle(45);
$p1->SetTheme('earth');

$p1->value->SetFont(FF_FONT1,FS_BOLD);
$p1->SetLabelType(PIE_VALUE_PER); 

$legends = array('None','WEP','WPA');

$p1->SetLegends($legends);



$a = array_search(max($data),$data); //Find the position of  maixum value.
$p1->ExplodeSlice($a);

$graph->Add($p1);
$graph->Stroke();
?> 

Edited by SQLpower

3
Contributors
9
Replies
12
Views
4 Years
Discussion Span
Last Post by LastMitch
0
$sqlTotal = "SELECT count(*) AS Number FROM students"; 
$total = mysql_query($sqlTotal);
while($resultTotal = mysql_fetch_array($total))
{
    $totalValue = $resultTotal['Number'];
}
$data = array($totalValue);

OK, so you're just getting a single value from the DB. You don't need a while loop for this. Are you sure that you're getting data from the db?

Try an

echo $resultTotal['Number'];
0

Hello, thank you for your response.

Well, I am just getting an error "The image cannot be dispalyed, because it contains errors."

Still trying to figure out where the problem is.

0

@SQLpower

Well, I am just getting an error "The image cannot be dispalyed, because it contains errors."

Read this about that error:

http://jpgraph.net/doc/faq.php#F4-12

Can you post the code that include your header() function.

0

Well, thanks for the info. I changed it a lil bit now and I am a getting: ( ! ) Parse error: syntax error, unexpected $end in C:\wamp\www\Charts\count.php on line 77

 <?php


include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph.php");   
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_pie.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/src/jpgraph_pie3d.php");
include ("c:/wamp/www/Charts/jpgraph-3.5.0b1/db.inc");




 $connect = mysql_connect("localhost","root","");
// Set the active mySQL database
$db_selected = mysql_select_db("test", $connect);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

$sql = "SELECT  * FROM students";
$RESULT = mysql_db_query("test","$sql",$connect);
$records = mysql_num_rows( $RESULT);
// echo $records; // number of unique urls



for($i=0;$i<$records;$i++) // for every unique url read the next lines
{
$rows = mysql_fetch_row($RESULT);
$servicearea = $rows[0];

$sqlTotal = "SELECT count(*) AS Number FROM students";
$total = mysql_query($sqlTotal); 

$data = array($qlTotal);
//print_r($data); 



while($resultTotal = mysql_fetch_array($total))
{
$totalValue = $resultTotal['Number'];
}
$time= date('m/d/y'.' @ '.'g:i a');

$data = array($sqlTotal);
//print_r($data);

$graph = new PieGraph(510, 350,"auto");
$graph->SetShadow();
$graph->title->Set("Matrix of Services Rendered--Last Updated $time");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->SetColor('silver@0.1' );

$p1 = new PiePlot3D($data);
$p1->SetSize(.3);
$p1->SetCenter(0.50);
$p1->SetStartAngle(90);
$p1->SetAngle(60);
$p1->SetTheme('earth');

$p1->value->SetFont(FF_FONT1,FS_BOLD);
$p1->SetLabelType(PIE_VALUE_PER);

$legends = array('Students');
//print_r($legends);

$p1->SetLegends($legends);

$a = array_search(max($data),$data); //Find the position of maixum value.
$p1->ExplodeSlice($a);//(array(25,75,50,20));

$graph->Add($p1);
$graph->Stroke();



?>

Edited by SQLpower

0

@SQLpower

Well, thanks for the info. I changed it a lil bit now and I am a getting: ( ! ) Parse error: syntax error, unexpected $end in C:\wamp\www\Charts\count.php on line 77

On line 26 & 27

for($i=0;$i<$records;$i++) // for every unique url read the next lines
{

You have a open bracket : {

but where is the close bracket : }?

Edited by LastMitch: grammer

0

@SQLpower

Still doesn't work, grr. Same error - contains errors.

May I ask you a question?

Why is your code that spacey?

I hope you realized that your code is a bit too spacey you have 3 lines space in between your <?php ?> tags. Try to close the gap to be on <?php ?> tags and the other lines too. So it looks more organized and presentable. With that much space it's hard to figure out rather it's a white space issue that causing the problem. Regarding about the close bracket : } You still need to put that bracket in order for it to work.

You can read more about it here:

http://en.kioskea.net/faq/3377-parse-error-syntax-error-unexpected-end

0

Well, my teacher was a little bit weird alyways leaving tons of spaces between each line so I kinda picked it up, I know sometimes is annoying. Yeah, thanks for pointing the bracket out. I closed it and I get an error "Image cannot be displayed because it contains errors".

So I am still stuck with that thingy :(

Edited by SQLpower

0

@SQLpower

I closed it and I get an error "Image cannot be displayed because it contains errors".

So I am still stuck with that thingy :(

Did you read this carefully:

http://jpgraph.net/doc/faq.php#F4-12

I post couple of lines from that link:

First of all this is an error message from the browser and not the library.

The solution is to disable output-buffering until You are convinced that Your code is without any problem. On a develpment server it is recommended to always have output buffering disabled.

You still didn't post your header code

Here is what I'm talking about:

header("Content-type:image/png");

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.