title: how to write select query using if condition,And condition and where condition in codeigniter
body: <p>HI CI developers i am new to Ci so request you people to help me in developing a project which i had already developed using core php. So now i am interested to learn codeigniter so trying to develop same matrimonial project using ci framework. In core php i had written a search query which now i want to write it CI format so please help me guys<br>
  <strong>THIS IS MY HTML PAGE</strong>   </p>
  
  <pre><code>&lt;form action="&lt;?php echo base_url();?&gt;searchresult/users" method="post"&gt;
  &lt;div id="tab1" class="tab_content" &gt;
  **strong text** 
  &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt; 
  &lt;tr&gt;
    &lt;td&gt;Looking for&lt;/td&gt; 
    &lt;td&gt; &lt;input type="radio" name="look" id="look" value="female" checked="checked"/&gt; 
       &lt;span style="color:#000000;"&gt;Bride&lt;/span&gt; 
       &lt;input type="radio" name="look" id="look" value="male" /&gt;
       &lt;span style="color:#000000;"&gt; Groom&lt;/span&gt;
    &lt;/td&gt; 
  &lt;/tr&gt; 
  &lt;tr&gt; 
    &lt;td&gt;Age&lt;/td&gt; 
    &lt;td&gt; &lt;span style="color:#000000;"&gt;From &lt;/span&gt; 
      &lt;select name="age_from" id="age" class="inp_age" &gt; 
         &lt;option&gt;21&lt;/option&gt; &lt;option&gt;22&lt;/option&gt; 
         &lt;option&gt;23&lt;/option&gt; &lt;option&gt;24&lt;/option&gt; 
         &lt;option&gt;25&lt;/option&gt; &lt;option&gt;26&lt;/option&gt;
        &lt;/select&gt;
     &lt;span style="color:#000000;"&gt;&amp;nbsp; To&lt;/span&gt;
     &lt;select name="age_to" id="age" class="inp_age" &gt; 
      &lt;option&gt;18&lt;/option&gt;
      &lt;option&gt;19&lt;/option&gt; 
      &lt;option &gt;20&lt;/option&gt;
      &lt;option selected="selected"&gt;70&lt;/option&gt; 
     &lt;/select&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt; 
     &lt;td&gt;Sect&lt;/td&gt; 
     &lt;td&gt;&lt;select name="sect" id="sect" onchange="return SelectSect(this.value);" class="inp_search" &gt;
   &lt;!-- &lt;select name="cont" id="cont" onchange="return SelectState(this.value);" class="inp"&gt;--&gt; 
   &lt;option value=""&gt;Any sect&lt;/option&gt;
   &lt;option value="&lt;?php echo $sects['sect_id'];?&gt;"&gt;&lt;?php echo $sects['sect_name'];?&gt;&lt;/option&gt; 
  &lt;/select&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt;
      &lt;td&gt;Sub Sect&lt;/td&gt; 
      &lt;td&gt;
        &lt;select name="subsect" id="subsect" onchange="return SelectSub(this.value);" class="inp_search" &gt; 
         &lt;option value=""&gt;Any subsect&lt;/option&gt; 
      &lt;/select&gt;
     &lt;/td&gt; 
   &lt;/tr&gt; 
   &lt;tr&gt; 
       &lt;td&gt;Country&lt;/td&gt;
       &lt;td&gt; 
           &lt;select name="country" id="country" onchange="return SelectState(this.value);" class="inp_search"&gt; 
            &lt;option value=""&gt;Any Country&lt;/option&gt; 
            &lt;option value="&lt;?php echo $country['country_id'];?&gt;" style="width:10px"&gt;&lt;?php echo $country['Country_name'];?&gt;&lt;/option&gt;
          &lt;/select&gt;
        &lt;/td&gt;
    &lt;/tr&gt; 
    &lt;tr&gt; 
       &lt;td&gt;State&lt;/td&gt; 
       &lt;td&gt;
           &lt;select name="state" id="state" onchange="return SelectCity(this.value);" class="inp_search" &gt; 
            &lt;option value=""&gt;Any state&lt;/option&gt;
           &lt;/select&gt;
       &lt;/td&gt;
    &lt;/tr&gt; 
     &lt;tr&gt;
        &lt;td&gt;City&lt;/td&gt; 
        &lt;td&gt;
           &lt;select name="city" id="city" class="inp_search" &gt; 
              &lt;option value=""&gt;Any city&lt;/option&gt;
         &lt;/select&gt;
        &lt;/td&gt; 
     &lt;/tr&gt; 
      &lt;tr&gt;
          &lt;td&gt;Qualification&lt;/td&gt;
          &lt;td&gt;
              &lt;select name="qualification" id="qualification" class="inp_search" &gt; 
                &lt;option value=""&gt;Any qualification&lt;/option&gt; 
                &lt;option value="&lt;?php echo $qualifications['qualification_id'];?&gt;"&gt;&lt;?php echo $qualifications['qualification'];?&gt;&lt;/option&gt; 
              &lt;/select&gt;
          &lt;/td&gt; 
     &lt;/tr&gt;
     &lt;tr&gt;
          &lt;td&gt;&amp;nbsp;&lt;/td&gt; 
          &lt;td&gt; &lt;div style="padding-left:100px;"&gt;
                     &lt;input type="submit" name="submit" class="button green search_btn" value="Search" /&gt;
              &lt;/div&gt;
         &lt;/td&gt; 
     &lt;/tr&gt; 
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>THIS IS MY CONTROLLER PAGE</strong>  </p>
  
  <pre><code> &lt;?php 
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
      class Searchresult extends CI_Controller { 
         public function __construct(){ 
           parent::__construct(); 
           $this-&gt;load-&gt;model('searchresultss','','TRUE');
         } 
         public function users() {
           $this-&gt;load-&gt;view('includes/kheader');
           $data['showdata'] = $this-&gt;searchresultss-&gt;login();
           $this-&gt;load-&gt;view('searchresult',$data);
           $this-&gt;load-&gt;view('includes/khelp'); 
           $this-&gt;load-&gt;view('includes/kfooter'); }
       } 
  </code></pre>
  
  <p><strong>THIS MY MODEL PAGE</strong>  </p>
  
  <pre><code>  &lt;?php 
    Class Searchresultss extends CI_Model {  
        function login() { 
          $this-&gt;db-&gt;select('*'); 
          $this -&gt; db -&gt; from('users'); 
          $query = $this-&gt;db-&gt;get()-&gt;result();
          return $query; 
         }
    } 
    **this i smy core php query**
      $per_page =3; 
      $members=mysql_query("SELECT * FROM users WHERE if('$se_ct'!='',sect = '$se_ct' AND
      if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND  
      subsect like '%%') AND IF( '$cou_ntry' !='', country = '$cou_ntry' AND if('$sta_te' 
      !='', state = '$sta_te' AND if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state 
      LIKE '%%' AND city LIKE '%%'), country LIKE '%%' AND state LIKE '%%' AND city LIKE 
      '%%' ) AND age &gt;= '$age_from' AND age &lt;= '$age_to' AND IF('$qualification' 
      !='',qualification = '$qualification', qualification LIKE '%%' ) AND gender = 
      '$look' And status='1' "); 
     $count =mysql_num_rows($members);
     $pages =ceil($count/$per_page); 
  </code></pre>
  
  <p>i need $count and $pages result too so guys help me in writing controller and model for above given details</p>