title: search function using framework codeigniter, php
body: <p>my problem is i whenever i input <code>fname</code> and <code>mname</code> i got an error from the database. i just want to search both of <code>fname</code> and <code>mname</code> in search field. </p>
  
  <p>my <code>search</code> controller function</p>
  
  <pre><code>  public function search()
    {
      $li = $this-&gt;session-&gt;userdata('logged_in');
      $id = $this-&gt;session-&gt;userdata('idnumber');
      if($li == TRUE)
      {
        $this-&gt;load-&gt;model('users_model');
        $this-&gt;load-&gt;helper('smiley');
        $this-&gt;load-&gt;library('table');
        $image_array = get_clickable_smileys('http://localhost/efg/images/smileys', 'status');
        $col_array = $this-&gt;table-&gt;make_columns($image_array, 8);
        $image_array2 = get_clickable_smileys('http://localhost/efg/images/smileys', 'status');
        $col_array2 = $this-&gt;table-&gt;make_columns($image_array2, 8);
        $this-&gt;data['smiley_table1'] = $this-&gt;table-&gt;generate($col_array);
        $this-&gt;data['smiley_tables'] = $this-&gt;table-&gt;generate($col_array2);           
        if($this-&gt;input-&gt;post())
        {
          $search = $this-&gt;input-&gt;post('search');
          $memb = $this-&gt;users_model-&gt;search($search);
          $usersearch =  $this-&gt;users_model-&gt;search($search);
          $grpsearch =  $this-&gt;users_model-&gt;searchgrp($search);
          redirect ('home/profile/'.$memb);
        }
      }
   }
  </code></pre>
  
  <p><strong>My <code>users_model</code> model</strong></p>
  
  <pre><code> public function search($search)
   {
     $this-&gt;db-&gt;select('*');
     $this-&gt;db-&gt;from('users');
     $this-&gt;db-&gt;like('username',$search);
     $this-&gt;db-&gt;or_like('fname',$search);
     $this-&gt;db-&gt;or_like('lname',$search);
     $this-&gt;db-&gt;or_like('mname',$search);
     $query = $this-&gt;db-&gt;get();
     foreach ($query-&gt;result_array() as $row)
     {
        $memb = $row['idnumber'];
     }
     $error = 'There is no record for the one you searched. Please go Back.';
     $query1 = $this-&gt;db-&gt;query("SELECT * FROM users WHERE idnumber ='$memb'");
     $hehe = $query1-&gt;result_array();
     if($hehe==NULL)
     {
       echo $error; exit;  
     }
     else 
     {
      return $memb;
     }
   }
  </code></pre>