Page 1 of 1

OO - Switch or Additional Function

Posted: Tue Jun 17, 2008 1:16 pm
by psurrena
In the below class, say I wanted to add two more queries, would it be better to add "peopleQuery()","placeQuery()" functions or have just one query function with that switches "querySelect("place")"?

Thanks.

Code: Select all

class NewProject{
    protected $pid;
    protected $query;
    protected $errorMsg="";
    
    public function __construct(){
        $this->pid=$_GET['id']; 
    }
        
    public function projectQuery(){
        $this->query="SELECT project_id, project_name, project_des
            FROM project 
            WHERE project_id='$this->pid'";
            
        return $this->query;
    }
    
    public function queryResults(){
        $result=mysql_query($this->query) or die (mysql_error());
        if($result){
            $row=mysql_fetch_assoc($result);
        }else{
            $this->errorMsg="Sorry, this project does not exist";
        }       
        return $row;
    }
}

Re: OO - Switch or Additional Function

Posted: Tue Jun 17, 2008 1:33 pm
by Christopher
I would have separate methods...