Query question

How can I do the following

I have a for as follows
<% form_tag companies_path, :method => 'get' do %>

  <tr>
            <td style="width:150px;">Province: </td>
            <td><%= hidden_field_tag :test, "test" %>
<%= select_tag "province", "<option></option>
<option>Prince Edward Island</option>
<option>New Brunswick</option>
<option>Nova Scotia</option>
<option>Newfoundland</option>" %>
</td>
          </tr>
          <tr>
            <td>Product Category: </td>
            <td></td>
          </tr>
          <tr>
            <td colspan="2">
              <table>
                <tr>
                  <td>
                    <table><tr>
                        <td><%=check_box_tag :wood_based_panels, 1,
params[:wood_based_panels] %> Wood based panels</td>
                      </tr>
                      <tr>
                        <td><%=check_box_tag :pre_fabricated, 1,
params[:pre_fabricated] %> Complete pre-fabricated building and
houses</td>
                      </tr>
                      <tr>
                        <td><%=check_box_tag :wood_cabinets, 1,
params[:wood_cabinets] %> Wood kitchen cabinets</td>
                      </tr>
                      <tr>
                        <td><%=check_box_tag :wood_windows_doors, 1,
params[:wood_windows_doors] %> Wood windows and doors</td>
                      </tr>
                      <tr>
                        <td><%=check_box_tag :wood_flooring, 1,
params[:wood_flooring] %> Wood flooring</td>
                      </tr>
<tr>
            <td></td>
            <td><%= submit_tag "search", :name => nil %></td>
          </tr>
        <% end %>

I want to dynamically build the SQL statement to look something like
this
SELECT * FROM `companies` WHERE (0=0 and province = Prince Edward
Island and (pre_fabricated = 1or wood_based_panels = 1))
The values in the where statement can change based on what is selected
in the form.

My Model
if search[:test]
      #province = search.delete(:province)
      test = search.delete(:test)
      action = search.delete(:action)
      controller = search.delete(:controller)
      sql = "0=0"
      search.each do |key, val|
        if[:province]
          sql += " and #{key} = #{val}"
        else
          sql += "and (#{key} = #{val} or"
        end
         sql += ")"
      end
      find(:all, :conditions => [sql])
    else
      find(:all)
    end
  end

This is not working Please help!!