Jump to content

Is it possible to call a method twice in a automated script?


Shabalaka

Recommended Posts

Hi Guys

 

Im having a problem with a couple of methods in my class.

 

This class reads a CSV file and the iterates each line and seperates all the values into an array which we manipulate later on.

 

These are the 2 methods im trying to get running.

 

 

public function GetID($table,$value,$field){ 
        // This will retrieve any ID,s we need to get back from a table 
        $sql = "SELECT * FROM `".$table."` WHERE `".$field."`= '".$value."'"; 
        $query = mysql_query($sql); 
        $numrows = mysql_num_rows($query); 
         
        if($numrows == 0){ 
             
            // If we have no rows returned we need to enter the info and run GetID again. 
                $insertnewrow = "INSERT INTO `".$table."`(`".$field."`) VALUES ('".$value."')"; 
                $insertquery = mysql_query($insertnewrow)or die(mysql_error()); 
                //Run this function again to get the newly inserted ID and perform switch to assign ID. 
                //echo "<BR>". $value ." was not found in ".$table." So we have inserted it and now are running the GetID again<br>"; 
                //$this->GetID($table,$value,$field); 
                 
            switch($table){ 
                //If we want the tablea table 
                case "tablea": 
                    //Assign The Domain ID to the Class ID. 
                    $this->Domain_ID = mysql_insert_id(); 
                    break; 
                    //If we are searcing in the links table we are prolly looking for a target domain id. 
                case "tableb": 
                    //assign the link id 
                    $this->link_id =mysql_insert_id(); 
                    break; 
                    // We are going to get the target domain id. 
                case "tablec": 
                    $this->Target_Domain_id =mysql_insert_id(); 
                    break; 
                default : 
                    echo "<div id  = 'unknowntable'>Im sorry we are having trouble querying the table : ".$table." , Are you sure it exists in the database??</div>"; 
                 
            } 
                 
            } 
            $result = mysql_fetch_array($query) or die ( mysql_error()); 
        // Now we perform a switch to set the class dependant on the table selected. 
         
            switch($table){ 
                //If we want the limomail_domains table 
                case "tablea": 
                    //Assign The Domain ID to the Class ID. 
                    $this->Domain_ID = $result['id']; 
                    break; 
                    //If we are searcing in the links table we are prolly looking for a target domain id. 
                case "tableb": 
                    //assign the link id 
                    $this->link_id = $result['id']; 
                    break; 
                    // We are going to get the target domain id. 
                case "tablec": 
                    $this->Target_Domain_id = $result['id']; 
                    break; 
                default : 
                    echo "<div id  = 'unknowntable'>Im sorry we are having trouble querying the table : ".$table." , Are you sure it exists in the database??</div>"; 
                 
            } 
         
             
         
         
     I would just like to add that im trying to run the Method GetID Twice so i have no need to call it twice in the PHP page as it runs it automatically, Im relatively new to OOP php so am trying to design a few "automated" classes to perform things.

My thinking is that once GetID has run once it goes back to the break_domains function and trys to run that next GetID    
         
    } 
public function break_domains(){ 

$this->GetID("tableb",$this->Domain_Name,"domain"); 
            //Once this is run check for a Domain Name been set 
            echo "<BR>Running GetID From the break_domains function <br>"; 
            $this->GetID("tableb",$this->Target_Name,"domain"); 
} 

 

Now whats happening is it will run once and insert the new Domain Name but then when i try to run GetID again it wont do it , If i run the script a second time it does enter the new target name and then eventually if i run script a 3rd time i will recieve the output im looking for :S

 

I would just like to add that im trying to run the Method GetID Twice so i have no need to call it twice in the PHP page as it runs it automatically, Im relatively new to OOP php so am trying to design a few "automated" classes to perform things.

 

My thinking is that once GetID has run once it goes back to the break_domains function and trys to run that next GetID

 

Many Thanks for any replys

Link to comment
Share on other sites

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.