Jump to content

Hi, my Pie class is not working , why ?...pls see below...


Recommended Posts

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...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.