jd2007 Posted August 12, 2007 Share Posted August 12, 2007 this is the code: <?php class Graphs { private $host; private $username; private $password; private $db; private $server; private $selectdb; private $img; private $width; private $height; private $funct; private $type; private $source; private $srcx2; private $srcy2; function _construct($h, $u, $p, $d, $w, $h) { $this->host=$h; $this->username=$u; $this->password=$p; $this->db=$d; $this->width=$w; $this->height=$h; } function connectdb() { $this->server=mysql_connect($this->host, $this->username, $this->password); $this->selectdb=mysql_select_db($this->db, $this->server); } function createimg($typeb=" ", $sourceb=" ", $srcx2b=" ", $srcy2b=" ") { $this->type=$typeb; if ($this->type=="truecolor") { $this->funct="imagecreate".$this->type; $this->img=$this->funct($this->width, $this->height); } else if ($this->type=="gd2part") { $this->funct="imagecreatefrom".$this->type; $this->img=$this->funct($this->source, $this->srcx2, $this->srcy2, $this->width, $this->height); } else if ($this->type=" ") { $this->funct="imagecreate"; $this->img=imagecreate($this->width, $this->height); } else { $this->funct="imagecreatefrom".$this->type; $this->img=$this->funct($source); } } function coloralloc($a, $b, $c) { $this->x=$a; $this->y=$b; $this->z=$c; $this->alloc=imagecolorallocate($this->img, $this->x, $this->y, $this->z); } function text($txt1, $txt2, $txt3, $txt4, $txt5, $txt6, $txt7) { $this->size=$txt1; $this->angle=$txt2; $this->x2=$txt3; $this->y2=$txt4; $this->color=$txt5; $this->font=$txt6; $this->text=$txt7; $this->string=imagettftext($this->img, $this->size, $this->angle, $this->x2, $this->y2, $this->color, $this->font, $this->text); } function destruct2() { imagepng($this->img); imagedestroy($this->img); } } class Pie extends Graphs { private $datas1; private $datas2; private $keys; private $flag; private $num; private $info; function tabledata($arr1, $arr2) { $this->datas1=$arr1; $this->datas2=$arr2; for ($i=0; $i<count($this->datas1); $i+=2) { $i=$j; $this->keys[]=$this->datas[$j]; $this->flag[]=$this->datas[$j++]; } foreach ($this->datas2 as $data) { $this->num +=(int) $data; } foreach ($this->datas2 as $data2) { $this->info[] = ($data2/$this->num)*360; } } } $graph=new Pie("localhost", "root", "jd2008", "graphexample", "100", "100"); $graph->connectdb(); $graph->createimg(); $graph->coloralloc("200", "100", "100"); $graph->destruct2(); ?> i get this output: ------------------------------------------------------------------- Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\AppServ\www\Graphing Tools\graphclass.php on line 30 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\Graphing Tools\graphclass.php on line 31 Warning: imagecreate() [function.imagecreate]: Invalid image dimensions in C:\AppServ\www\Graphing Tools\graphclass.php on line 50 Warning: imagecolorallocate(): supplied argument is not a valid Image resource in C:\AppServ\www\Graphing Tools\graphclass.php on line 64 Warning: imagepng(): supplied argument is not a valid Image resource in C:\AppServ\www\Graphing Tools\graphclass.php on line 81 Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\AppServ\www\Graphing Tools\graphclass.php on line 82 -------------------------------------------------------------------------- i think there is a problem with the constructor...not sure though...pls help... Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/ Share on other sites More sharing options...
GingerRobot Posted August 12, 2007 Share Posted August 12, 2007 i think there is a problem with the constructor...not sure though...pls help... Quite possibly. Are you using php5? Before php5 the constuctor function had the same name as the class, rather than being called __construct. Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321499 Share on other sites More sharing options...
jd2007 Posted August 12, 2007 Author Share Posted August 12, 2007 i'm using php5 Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321501 Share on other sites More sharing options...
GingerRobot Posted August 12, 2007 Share Posted August 12, 2007 Oh, i just noticed, you've called your constructor '_construct' its '__construct' - a double underscore. Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321502 Share on other sites More sharing options...
jd2007 Posted August 12, 2007 Author Share Posted August 12, 2007 thank u Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321503 Share on other sites More sharing options...
jd2007 Posted August 12, 2007 Author Share Posted August 12, 2007 the ouput is this : ‰PNG ��� IHDR���d���ú���m@p$���PLTEÈddsˆñÀ���IDATxœíÁ1��� õOm ���x3 ¬�dï%ò����IEND®B`‚ why ? Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321506 Share on other sites More sharing options...
Barand Posted August 12, 2007 Share Posted August 12, 2007 I didn't spot a header("content-type: image/png"); Quote Link to comment https://forums.phpfreaks.com/topic/64496-hi-my-pie-class-is-not-working-why-pls-see-below/#findComment-321609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.