views:

23

answers:

1

hi, I am trying to use like in zend

switch($filter2) { case 'name': switch($filter1) { case 'start_with': $search = "\"pd_name like ?\", '$patient_search_name%'"; break;

                                case 'contains':
                                $search = "'pd_name  like ?', '%$patient_search_name%'";
                        break;

                                case 'exact_match': 
                                $search = "'pd_name = ?', $patient_search_name";
                        break;  
                        }
        break;

        case 'phone':
                        switch($filter1)
                        {
                                case 'start_with':
                                $search = "'pd_phone  like ?', '$patient_search_name%'";
                        break;

                                case 'contains': 
                                $search = "'pd_phone  like ?', '%$patient_search_name%'";
                        break;

                                case 'exact_match': 
                                $search = "'pd_phone = ?', $patient_search_name";
                        break;  
                        }
   break;

}
    $select = $this->getDbTable()->select()
                   ->from("patient_data",
                        array('*'))
                       ->where("$search");

but when i see the query log its like

SELECT `patient_data`.* FROM `patient_data` WHERE ("pd_name  like ?", 'bhas%')

where as the ? should have been replaced by the value ....how to solve this??

A: 

That will not work. If you want the placeholder to be substituted you will need to pass in two parameters to where(), e.g.:

->where('pd_phone = ?', $patient_search_name);

Otherwise, the single string you are passing will be used for the where clause as-is, so you would need to do something like:

$search = "pd_phone = " . $patient_search_name;

That is to say, build the entire where clause as a single string. Alternatively, use the select object within the switch statement, e.g.:

case 'exact_match': $select->where('pd_name = ?', $patient_search_name);
                     break;  

Or just have two variables in each case, e.g.:

$placeholder = "pd_phone = ?";
$value = '%' . $patient_search_name . '%';
break;
...
->where($placeholder, $value);
karim79
oh okie i got it..now what i had written zend is treating like a single variable..... i did a workaround and write like $search = "pd_name like '%$patient_search_name%'"it worked....hope its proper...
pradeep