views:

49

answers:

1

I have a function in my model that I need to use multiple conditions when querying. Additionally I would like to also have partial matches.

I currently have:

public function searchClient($search_term)
{
$rows = $this->fetchAll(
    $this->select()
    ->where('first_name = ?', $search_term)
    );  
    return $rows->toArray();
}

Which is the equivalent of "SELECT * FROM clients WHERE first_name = 'foobar';"

I would like to have a function that is the equivalent of "SELECT * FROM clients WHERE first_name LIKE '%foobar%' OR last_name LIKE '%foobar%' OR home_phone LIKE '%foobar%';"

How would I create such a query within Zend_Db_Table?

+1  A: 
public function searchClient($search_term)
{
    $rows = $this->fetchAll(
        $this->select()->where('first_name LIKE ?', "%$search_term%")
                       ->orWhere('last_name LIKE ?', "%$search_term%")
                       ->orWhere('home_phone LIKE ?', "%$search_term%")
        ); 
    return $rows->toArray();
}
karim79
Beautiful!!! Works perfectly.
Mario