Hi

I have been trying for a long time to "learn" how to do this but tutorials only go so far and I haven't found anyone to hold my hand through it yet (well my husband but he only uses the computer to play pool :rolleyes: )

Here is what I would like to do - if this is not possible please let me know so I can put it to sleep.

class Dog {

var = $dog_id;

function Dog($dog_id) {

this->dog_id=$dog_id;
}

function GetDetails {

retrieve stuff from db tables where id= this->dog_id;
echo name;
Return fields[mom_id and dad_id];
}
}

Now here is where I get lost. I have read that the Return stops the function but am not sure if it stops the class too. That's OK as this is all I need the class to do but can I have the class do the Return so that the variable for the parents ID can be used outside of the "object"? If so how is that written so that I can give a variable name to the returned values?

Additionally can I use different variable names for the Return with each occurance of the class and with multiple occurances on the same page.

Part of my brain says this should be relatively simple - but I still can't figure it out. Help in figuring this out would be greatly appreciated.

Connie

    returns don't stop the class... only the current function that the return is in.

    Not sure what you're asking.... if you're returning a value, just do:

    $object = new Dog;
    
    $fields = $object->GetDetails();

      returns don't stop the class... only the current function that the return is in.

      Not sure what you're asking.... if you're returning a value, just do:

      PHP Code:
      $object = new Dog; 
      
      $fields = $object->GetDetails(); 

      Thanks bpat1434

      Sort of like this

      $dog1 = new Dog($_GET(dog_id)
         return parent ids as $sire and $dam;  (sorry not sure of the syntax)
      
      $dog2 = new Dog($sire)
         return parent ids as $sire_grandsire and $sire_granddam;
      
      $dog3 = new Dog($dam)
         return parent ids as $dam_grandsire and $dam_granddam;
      
      $dog4 = new Dog($sire_grandsire)
         return parent ids as $sire_Ggrandsire and $sire_Ggranddam;
      
      etc....

      Each time the object is used it will create 2 new variables with unique names which will in turn be used as this->dog_id later on the same page.

      I hope that makes a little more sense

      Connie

        No.... not exactly....

        You instantiate the object (which you do with $dog1-4).... Then, just create a new variable, and reference the function of the object you created.

        Now, if your object automatically returns an ID (i.e. when you instantiate it, it calls an internal function that returns the id) then $dog1-4 will hold the IDs you want.

        Otherwise, you'd need to do as I first posted and instantiate the object, then create a new variable and call the internal function from the object as a new variable.

        $object = new Dog($_GET['something']); // Instantiate the object
        $id = $object->getDetails();// Will hold the ID

          Ok - something seems to be clicking but let me make sure I'm understanding:

          $dog1 = new Dog($_GET['something']); // Instantiate the object 
          $sire = $dog1->getDetails(sire_id);// or $sire_id as set up inside class function
          $dam = $dog1->getDetails(dam_id);// 
          
          
          $dog3 = new Dog($sire); //
          $sire_gsire = $dog3->getDetails(sire_id);// 
          $sire_gdam = $dog3->getDetails(dam_id);// 
          
          etc...

          Connie

            Thank you very much. Will work on putting this all together.

            ummm... are you truly vehicleless? pm me - I might be able to help.

            Connie

              Write a Reply...