Web Analytics Made Easy -
StatCounter objects and classes - CodingForum

Announcement

Collapse
No announcement yet.

objects and classes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • objects and classes

    hello im stuck and i need your help please

    Problem:

    i have a template class for a graph and i want to import information to the template to create multiple graphs with different statistics. here is my code:

    PHP Code:
    <?PHP
    //get all class files required

    require "dbConnect.php"
    $conn = new dbConnect();

    require 
    "getData_cls.php";
    $myData = new data();
     
    require 
    "shape_cls.php";
    $displayGraph = new shape();

    //get data from classes

    $connection $conn->connect();

    $countMen $myData->getMen($connection);
    $countWomen $myData->getWomen($connection);

    $countStirAttendeeYes $myData->getStirAttendeeYes($connection);
    $countStirAttendeeNo $myData->getStirAttendeeNo($connection);

    //describe data in context of graph

    if($countMen && $countWomen){
        
        
    $displayGraph->dataAlpha $countMen;
        
    $displayGraph->dataBeta $countWomen;
        
    $displayGraph->title 'Gender';
        
    $displayGraph->dataKeyAlpha 'Men';
        
    $displayGraph->dataKeyBeta 'Women';
        
        
    $displayGraph->graph();
    }
    if(
    $countStirAttendeeYes && $countStirAttendeeNo){
        
        
    $displayGraph->dataAlpha $countStirAttendeeYes;
        
    $displayGraph->dataBeta $countStirAttendeeNo;
        
    $displayGraph->title 'Stirling Uni Attendees';
        
    $displayGraph->dataKeyAlpha 'Yes';
        
    $displayGraph->dataKeyBeta 'No';

        
    $displayGraph->graph();
    }


    ?>
    the graph class files is:

    PHP Code:
    <?PHP
    class shape{
        
        var 
    $dataAlpha;
        var 
    $dataBeta;
        var 
    $title;
        var 
    $dataKeyAlpha;
        var 
    $dataKeyBeta;
    /**************************************************************************
                    function graph
    ***************************************************************************/

        
    function graph(){
            
    $dataAlpha trim($this->dataAlpha);
            
    $dataBeta trim($this->dataBeta);
            
    $title trim($this->title);
            
    $dataKeyAlpha trim($this->dataKeyAlpha);
            
    $dataKeyBeta trim($this->dataKeyBeta);

        
    /*for the y axis when describing shapes use the height-value to make it easier to work out*/
            
            
    $height 150;        
            
    $width 200;    

            
    $countTotal $dataAlpha $dataBeta;
            
    $perCentAlpha floor($dataAlpha $countTotal 100);
            
    $perCentBeta floor($dataBeta $countTotal 100);

            
    $titlePos $width-190;

            
    $image imagecreate($width,$height);
            
    $grey ImageColorAllocate($image,210,210,210);
            
            
    $blue ImageColorAllocate($image,0,130,255);
            
    $pink ImageColorAllocate($image,255,0,240);
            
    $white ImageColorAllocate($image,255,255,255);
            
    $black ImageColorAllocate($image,0,0,0);

            
    imageString($image5$titlePos$height-140$title$black); //title
            
                    
            
            
    imageFilledRectangle($image,10,$height-$perCentAlpha,30,$height-10,$blue);        //bar to represent men

            
    imageFilledRectangle($image,40,$height-$perCentBeta,60,$height-10,$pink);        //bar to represent women

            
    imageFilledRectangle($image,8,$height-100,9,$height-0,$black);                        //y axis

            
    imageFilledRectangle($image,0,$height-9,70,$height-8,$black);                        //x axis

            
    imageString($image5100$height-50,  "$dataKeyAlpha".': '."$perCentAlpha".'%'$blue); //info
            
    imageString($image5100$height-35,  "$dataKeyBeta".': '."$perCentBeta".'%'$pink); //info

            
    header ("Content-type: image/png");
            
    ImagePng($image); 
            
    ImageDestroy($image);
        }
    //end graph function
        

    }//end class
    ?>
    essentialy i have to create multiple instances of the graph class and I think its something to do with constructors and stuff but im not sure.

    any help appreciated.
    slh

  • #2
    Well... I didn't read all the code... but what is your problem?
    www.united-scripts.com
    www.codebattles.org

    Comment


    • #3
      you should create a constructor: (in shape_cls.php) :

      PHP Code:
      function shape() {
      return;


      but you should be able to create multiple instances...

      you created the object $displayGraph, and then have it performing functions. Why not create other variables like $otherDisplayGraph or $displayGraph2 ??

      Comment


      • #4
        i tried that but it doesnt seem to make any difference:

        PHP Code:
        if($countMen && $countWomen){
            
        $displayGraph = new shape();

            
        $displayGraph->dataAlpha $countMen;
            
        $displayGraph->dataBeta $countWomen;
            
        $displayGraph->title 'Gender';
            
        $displayGraph->dataKeyAlpha 'Men';
            
        $displayGraph->dataKeyBeta 'Women';
            
            
        $displayGraph->graph();
        }

        if(
        $countStirAttendeeYes && $countStirAttendeeNo){
            
        $displayGraph2 = new shape();

            
        $displayGraph2->dataAlpha $countStirAttendeeYes;
            
        $displayGraph2->dataBeta $countStirAttendeeNo;
            
        $displayGraph2->title 'Stirling Uni Attendees';
            
        $displayGraph2->dataKeyAlpha 'Yes';
            
        $displayGraph2->dataKeyBeta 'No';

            
        $displayGraph2->graph();

        am i doing something wrong?
        I also added the constructor but it hasnt helped either.
        any other ideas?

        thanks so far guys
        slh

        Comment


        • #5
          so....you're not getting anything displayed by your calls to functions on the second object?

          inside your "if" statment

          PHP Code:
          ...
          if(
          $countStirAttendeeYes && $countStirAttendeeNo){
          ... 
          stick a
          PHP Code:
          print "testing<br/>\n"
          to make sure that the condition you're evaluating is evaluating as true.

          Comment


          • #6
            cheers for that. they were being drawn over one another so i couldnt see them.

            trying to figure out how to specify where the image is drawn on the page!!

            thanks so far
            slh

            Comment

            Working...
            X