Cool Graphs Don't Work Because I Can't Connect to Database - Joomla! Forum - community, help and support
hi all,
i trying connect database directly website via php script (below) extract data table , display graph. problem cannot connect mysql database. know of localhost, password , dbname info correct because can connect database via phpmyadmin. please explain possible reasons why cannot connect.
thanks
scotchontherocks
include ("c:/jpgraph-1.12.2/src/jpgraph.php");
include ("c:/jpgraph-1.12.2/src/jpgraph_bar.php");
$db = mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("test",$db) or die(mysql_error());
$sql = mysql_query("select * students") die(mysql_error());
while($row = mysql_fetch_array($sql))
{
$data[] = $row[1];
$leg[] = $row[0];
}
$graph = new graph(250,150,"auto");
$graph->setscale("textint");
$graph->img->setmargin(50,30,50,50);
$graph->adjbackgroundimage(0.4,0.7,-1); //setting bg type
$graph->setbackgroundimage("linux_pez.png",bgimg_fillframe); //adding image
$graph->setshadow();
$graph->xaxis->setticklabels($leg);
$bplot = new barplot($data);
$bplot->setfillcolor("lightgreen"); // fill color
$bplot->value->show();
$bplot->value->setfont(ff_arial,fs_bold);
$bplot->value->setangle(45);
$bplot->value->setcolor("black","navy");
$graph->add($bplot);
$graph->stroke(); ?>
i trying connect database directly website via php script (below) extract data table , display graph. problem cannot connect mysql database. know of localhost, password , dbname info correct because can connect database via phpmyadmin. please explain possible reasons why cannot connect.
thanks
scotchontherocks
include ("c:/jpgraph-1.12.2/src/jpgraph.php");
include ("c:/jpgraph-1.12.2/src/jpgraph_bar.php");
$db = mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("test",$db) or die(mysql_error());
$sql = mysql_query("select * students") die(mysql_error());
while($row = mysql_fetch_array($sql))
{
$data[] = $row[1];
$leg[] = $row[0];
}
$graph = new graph(250,150,"auto");
$graph->setscale("textint");
$graph->img->setmargin(50,30,50,50);
$graph->adjbackgroundimage(0.4,0.7,-1); //setting bg type
$graph->setbackgroundimage("linux_pez.png",bgimg_fillframe); //adding image
$graph->setshadow();
$graph->xaxis->setticklabels($leg);
$bplot = new barplot($data);
$bplot->setfillcolor("lightgreen"); // fill color
$bplot->value->show();
$bplot->value->setfont(ff_arial,fs_bold);
$bplot->value->setangle(45);
$bplot->value->setcolor("black","navy");
$graph->add($bplot);
$graph->stroke(); ?>
i have changed above code , appear connecting db - crashing @ line 25 while($row = mysql_fetch_array($database))
know why? here new code far:warning: mysql_fetch_array(): supplied argument not valid mysql result resource in /vhost/vhost4/l/y/n/lynnsdiets.co.uk/www/components/com_graph/graph.php on line 25
internal error: chosen locale file error messages not exist.
if (!defined('_valid_mos'))
die('direct access location not allowed.');
include ("jpgraph.php");
include ("jpgraph_bar.php");
$task = mosgetparam($_request, 'task', '');
global $mosconfig_absolute_path, $database, $db_name, $mosconfig_db, $sourcedir;
global $mosconfig_dbprefix,$db_prefix, $pm_on_reg, $use_realname, $cb_reg, $im, $agreement_required;
$database->setquery("
select `name`, `marks`
from #__students
");
while($row = mysql_fetch_array($database))
{
$data[] = $row[1];
$leg[] = $row[0];
}
$graph = new graph(250,150,"auto");
$graph->setscale("textint");
$graph->img->setmargin(50,30,50,50);
$graph->adjbackgroundimage(0.4,0.7,-1); //setting bg type
$graph->setbackgroundimage("linux_pez.png",bgimg_fillframe); //adding image
$graph->setshadow();
$graph->xaxis->setticklabels($leg);
$bplot = new barplot($data);
$bplot->setfillcolor("lightgreen"); // fill color
$bplot->value->show();
$bplot->value->setfont(ff_arial,fs_bold);
$bplot->value->setangle(45);
$bplot->value->setcolor("black","navy");
$graph->add($bplot);
$graph->stroke(); ?>
Comments
Post a Comment