Thread: Like queries
View Single Post
  #3 (permalink)  
Old 06-16-2008, 01:53 PM
bethgranter's Avatar
bethgranter bethgranter is offline
Junior Member
 
Join Date: Jun 2008
Location: Brighton
Posts: 1
Default

Hi, I'm very new to programming. I have a search form where users can type a string ($search_terms['search_term']) and select a field ($search_terms['field']) to search. If no field is selected, all columns in the database are searched ($this->view->comments is bringing back every column name). This was what I tried to do::

PHP Code:
 if (isset($search_terms)) {
            if (!empty(
$search_terms['field'])){
                
$select $this->mosaic->select()
                ->
where($search_terms['field'],"%".$search_terms['search_term']."%");
                
$select->order('structure_name');
            }
            else {
                
$select $this->mosaic->select();
                
$select->where("structure_name = ?","%".$search_terms['search_term']."%");
                foreach (
$this->view->comments as $fieldname => $comment) {
                    
$select->orWhere($fieldname ."= ?","%".$search_terms['search_term']."%");
                }
                
$select->order('structure_name');
            }
            
$this->view->results $this->mosaic->fetchAll($select);
        }
        else 
$this->view->results NULL;
    } 
The above works without any ."%" but of course only for exact matches, and I'd like to do it for any string containing the search term. Any clues as to what to do?

Last edited by bethgranter : 06-16-2008 at 01:58 PM. Reason: put php in php tags
Reply With Quote