OO - Switch or Additional Function

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

OO - Switch or Additional Function

Post 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;
    }
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: OO - Switch or Additional Function

Post by Christopher »

I would have separate methods...
(#10850)
Post Reply