Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-10-2008, 01:51 AM
Ewok's Avatar
Junior Member
 
Join Date: Mar 2008
Location: Colorado SPrings
Posts: 16
Send a message via MSN to Ewok Send a message via Yahoo to Ewok
Default Like queries

New to ZF.
Figured this out tonight. Thought it might help other people
Doing Mysql "LIKE" queries with Zend_Db_Table select

PHP Code:
$table = new Table();

$select $table->select();

$select->where("field_name like ?",$var."%"); 
__________________
Give all victory and gain to others
Take all defeat and loss upon yourself
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-10-2008, 02:32 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Welcome, Ewok. Good Tip.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-16-2008, 01:53 PM
bethgranter's Avatar
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:32 PM.