how to use PHPMyGraph5.0 to mysql php -


help please, have been searching months now. cant seem use phpmygraph5.0 mysql php. here's code.

//set content-type header header("content-type: image/png");  //include phpmygraph5.0.php include_once('phpmygraph5.0.php'); include('includes/dbconnect.php');  //set config directives $cfg['title'] = 'example graph'; $cfg['width'] = 400; $cfg['height'] = 200;  //set data $query="select         extract(month `table`.`datetime`) `date`,         count(distinct `table`.`id`) `count`         `table`         `table`.`datetime` between '2015-01-01' , '2015-12-31'         group `date`         order `date`";  $result = mysql_query($query) or die('query failed: ' . mysql_error());  if ($result) {     $data=array(     while ($row = mysql_fetch_assoc($result)) {         $month=$row["date"];         $count=$row["count"];         //add data areray         $dataarray[$month]=$count;     }  );  } //create phpmygraph instance $graph = new phpmygraph();  //parse $graph->parseverticalcolumngraph($data, $cfg); ?> 

i need able post graph compose of months , number of unique id per month. in code months $row["date"] , number of unique id $row["count"].

the graph should this.

this original code. , need code output array in code.

<?php         //set content-type header     header("content-type: image/png");      //include phpmygraph5.0.php     include_once('phpmygraph5.0.php');      //set config directives     $cfg['title'] = 'example graph';     $cfg['width'] = 400;     $cfg['height'] = 200;      //set data      //add data areray     $data = array      (          'jan'=>10,          'feb'=>20,          'mar'=>30,          'apr'=>100,          'may'=>20,          'june'=>110,          'july'=>50,         'aug'=>50,         'sept'=>50,         'oct'=>50,         'nov'=>50,         'dec'=>50,     );      //create phpmygraph instance     $graph = new phpmygraph();      //parse     $graph->parseverticalcolumngraph($data, $cfg); ?> 

if understood need connect mysql server , select database before calling mysql_query() function, rihgt?

that easy , can following code:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) {     die('couldn\'t connect: ' . mysql_error()); }  // database name $db_selected = mysql_select_db('databasename', $link); if (!$db_selected) {     die ('error in mysql_select_db(): ' . mysql_error()); } 

you can check out php documentation more. hoping helped you.

edit:

after more details looks problem not connecting database outputting graph. php pages outputs image can't load directly other php pages, should try output image generated php page in page using following code, in phpmygraph examples:

<img src="pagethatoutputsthegraph.php?data=somedata" alt="example code"> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -