# Data base search with advanced options

**URL:** <https://www.ruby-forum.com/t/data-base-search-with-advanced-options/125629>\
**Category:** Rails\
**Created:** [January 10, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/data-base-search-with-advanced-options/125629 "2008-01-10T19:28:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [January 10, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/data-base-search-with-advanced-options/125629/1 "2008-01-10T19:28:39Z")

</div>

How to approach this problem, i have a search form designed with  
multiselect list, checkboxes and so on.

I need to combine all these things together for a sql query.  
Let say the SQL from the options in the search form would be:

SELECT \* FROM users WHERE (name LIKE ‘%value%’ OR surname LIKE  
‘%value’ ) AND (account\_type = 1 OR account\_type=2) ORDER BY name ASC  
LIMIT 2,20

So the old way would be to do a string go thrught the params and make  
the sql above:  
string = “SELECT \* FROM users”  
if params[:options]  
string += " WHERE …"  
end  
if params …  
end

#and then the

users=User.find\_by\_sql(string)

Is the a object oriented approach without tons of if else statements??  
`
