Suraj Hazarika
Suraj Hazarika

Reputation: 667

Put a condition for a field within query

I have a sql query :

$cond = "";
    if($cid >0 )
    {
        $quali = $this->getCandidatesQualification($cid);

        $cond = "WHERE emp_qualification LIKE '%$quali%'";
    }

    $sql = "SELECT
            emp_job_id,emp_job_profie,emp_qualification,emp_experience
        FROM
            tbl_emp_data
            $cond
        ORDER BY job_add_date DESC LIMIT 0,10   
    ";
    $res = $this->db->returnArrayOfObject($sql,$pgin = 'no', $odr='no');

Now what I want if emp_qualification field is equal to any_graduate I want to select all the jobs for the candidate even if his qualification is say BA .

Upvotes: 0

Views: 57

Answers (2)

Jan S
Jan S

Reputation: 1837

so modify your WHERE clause to

WHERE emp_qualification LIKE '%$quali%' 
OR emp_qualification = 'any_graduate'

Upvotes: 1

Drew
Drew

Reputation: 6274

$cond = '';
if($cid >0 ) {
    if ($this->getCandidatesQualification($cid) != 'any_graduate') {
        $cond = "WHERE emp_qualification LIKE '%{$this->getCandidatesQualification($cid)}%'";
    }
}

simplified, try this

Upvotes: 0

Related Questions