title: How to fix this issue with advanced search codeigniter
body: <p>I want to build advanced search script but I have this error with search_all function in the model</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: 4096
  
  Message: Object of class CI_DB_mysql_result could not be converted to string
  
  Filename: models/search_model.php
  
  Line Number: 129
  </code></pre>
  
  <p>i have four fildes
  1- input text to write the book name
  2- select box for the author
  3- select box for the publisher
  3-select box for the section</p>
  
  <p>the model is</p>
  
  <pre><code>class search_model extends CI_Model
  {
      function __construct()
      {
          parent::__construct();
      }
      /* This function get all search in database sort by order asc.*/
  
      function get_new_one($id)
      {
  
      $this-&gt;db-&gt;where('ne_id',$id);
  
      $result=$this-&gt;db-&gt;get('d_search');
  
      return $result-&gt;row();
  
      }
      //////////////frontend//////////////////////////////////////////////////////////
  
      function show_new($id)
      {
  
      $result=$this-&gt;db-&gt;query("SELECT * , COUNT( d_comments_search.cn_new_id ) as count
  
                          FROM d_search
  
                          left JOIN d_comments_search ON d_search.ne_id = d_comments_search.cn_new_id and d_search.ne_hide='1'
  
                          inner join d_search_category on d_search_category.nc_id = d_search.ne_category_id and d_search_category.nc_hide= '1'
  
                          and d_search.ne_id= $id group by d_search.ne_id");
  
      return $result-&gt;row() ;
  
      }
  
      function generate_results($keyword,$row=0){
          $result1 = $this-&gt;db-&gt;query("SELECT bo_id,bo_name,bo_state,bo_about FROM d_book where (bo_name like '%$keyword%' or bo_about like '%$keyword%') and bo_state = '1' limit $row,20");
          $result2 = $this-&gt;db-&gt;query("SELECT au_id,au_name,au_state,au_info FROM d_author where (au_name like '%$keyword%' or au_info like '%$keyword%') and au_state = '1' limit $row,20");
          $result3 = $this-&gt;db-&gt;query("SELECT pub_id,pub_name,pub_state,pub_info FROM d_publishing where (pub_name like '%$keyword%' or pub_info like '%$keyword%') and pub_state = '1' limit $row,20");
          $results = array_merge($result1-&gt;result_array(),$result2-&gt;result_array(),$result3-&gt;result_array());
  
          return $results;
  
      }
  
      // get total number of users
      function getNumUsers($keyword)
      {
          $result1 = $this-&gt;db-&gt;query("SELECT bo_id,bo_name,bo_state,bo_about FROM d_book where (bo_name like '%$keyword%' or bo_about like '%$keyword%') and bo_state = '1'");
          $result1 = $result1-&gt;num_rows();
          $result2 = $this-&gt;db-&gt;query("SELECT au_id,au_name,au_state,au_info FROM d_author where (au_name like '%$keyword%' or au_info like '%$keyword%') and au_state = '1'");
          $result2 = $result2-&gt;num_rows();
          $result3 = $this-&gt;db-&gt;query("SELECT pub_id,pub_name,pub_state,pub_info FROM d_publishing where (pub_name like '%$keyword%' or pub_info like '%$keyword%') and pub_state = '1'");
          $result3 = $result3-&gt;num_rows();
          return $result1 + $result2 + $result3;
      }
      //////////////////////////////////end paging///////////////////
  
      function get_publishing()
      {
          $this-&gt;db-&gt;where('pub_state','1');
          $result=$this-&gt;db-&gt;get('d_publishing')-&gt;result_array();
          return $result;
      }
  
      function get_author()
      {
          $this-&gt;db-&gt;where('au_state','1');
          $result=$this-&gt;db-&gt;get('d_author')-&gt;result_array();
          return $result;
      }
  
      function get_section()
      {
          $this-&gt;db-&gt;where('sec_state','1');
          $result=$this-&gt;db-&gt;get('d_section')-&gt;result_array();
          return $result;
      }
  
      function search_name()
      {
          $bo_name=$_POST['bo_name'];
          $this-&gt;db-&gt;order_by("bo_ord","asc");
          $this-&gt;db-&gt;like('bo_name',$bo_name);
          return $this-&gt;db-&gt;get('d_book')-&gt;result_array();
  
      }
  
  
          function search_all() {
          $publish = $this-&gt;input-&gt;post('publish');
          $author = $this-&gt;input-&gt;post('author');
          $sec_name = $this-&gt;input-&gt;post('section');
  
          $sql = $this-&gt;db-&gt;query("SELECT * FROM `d_book`");
          $searches = array();
          if ($publish != 'choose')
              $searches[] = "`bo_pub_id` = '$publish'";
          if ($author != 'choose')
              $searches[] = "`bo_au_id` = '$author'";
          if ($sec_name != 'choose')
              $searches[] = "`bo_sec_id` = '$sec_name'";
          if (count($searches) &gt; 0) {
         $sql .= "WHERE " . implode(" AND ", $searches);
          }
          $sql .= ';';
  
  
      }
  
  
  }
  </code></pre>
  
  <p>this is controller</p>
  
  <pre><code>class Search extends front_end {
      var $temp;
  
      function __construct(){
         parent::__construct();
         $this-&gt;load-&gt;library('form_validation');
         //echo $this-&gt;input-&gt;post("keyboard");
  
      }
  
      public  function index()
      {
          $this-&gt;overview();
      }
  
      /**
       * This function display all  search
       * @param integer $row
       */
      public  function overview($row=0)
      {
          $this-&gt;form_validation-&gt;set_rules('keyword', 'ÙƒÙ„Ù…Ø© Ø§Ù„Ø¨Ø­Ø«', 'trim|required|xss_clean|htmlspecialchars');
          $this-&gt;form_validation-&gt;run();
          $this-&gt;store_keyword();
          //echo $this-&gt;session-&gt;flashdata('keyword');
          if ($this-&gt;session-&gt;flashdata('keyword') != ''){
              $keyword=$this-&gt;session-&gt;flashdata('keyword');
              $this-&gt;generate_results($this-&gt;session-&gt;flashdata('keyword'),$row);
          }else{
          $this-&gt;generate_results($this-&gt;input-&gt;post("keyword"),$row);
          }
          //$this-&gt;session-&gt;set_flashdata('keyword', $this-&gt;input-&gt;post("keyword"));
          $data = $this-&gt;temp;
  
          //$this-&gt;session-&gt;keep_flashdata('keyword');
          $this-&gt;view('search/site/results', $data);
      }
  
      /**
       * This function generate result of search
       * @param string $keyword
       * @param integer $row
       */
      public  function generate_results($keyword,$row=0){
          $this-&gt;load-&gt;model('search/search_model','search');
          $this-&gt;load-&gt;library('pagination');
          $config['base_url'] = base_url().'search/search/overview/';
          $config['total_rows'] = $this-&gt;search-&gt;getNumUsers($keyword);
          $config['per_page'] = '20';
          $config['uri_segment'] = '4';
          $this-&gt;pagination-&gt;initialize($config);
          $data['page'] = $row;
          $data['results'] = $this-&gt;search-&gt;generate_results($keyword,$row);
          $data['total_rows'] = $this-&gt;search-&gt;getNumUsers($keyword);
          $data['links']=$this-&gt;pagination-&gt;create_links();
          $this-&gt;temp = $data;
  
      }
  
      /**
       * This function display detail of new
       * @param integer $id
       */
      public  function show($id)
      {
          $data['new']=$this-&gt;search-&gt;show_new($id);
          $count=$data['new']-&gt;ne_count_visit;
          $this-&gt;search-&gt;add_count($count,$id);
          $data['comments']=$this-&gt;search-&gt;show_comments($id);
          $this-&gt;view('site/new', $data);
      }
  
      /**
       * This function store keyword to use in search 
       */
      private  function store_keyword(){
          if($this-&gt;input-&gt;post("keyword")){
             $this-&gt;session-&gt;set_userdata('keyword', $this-&gt;input-&gt;post("keyword"));
         }
      }
  
  
      public  function search_form()
      {
          $this-&gt;load-&gt;model('search/search_model','search');
          $data['publish']=$this-&gt;search-&gt;get_publishing();
          $data['author']=$this-&gt;search-&gt;get_author();
          $data['section']=$this-&gt;search-&gt;get_section();
          $this-&gt;view('search/site/adv_search_form',$data);
      }
  
      public function search_adv()
      {
         $this-&gt;load-&gt;model('search/search_model','search');
         $data['bo_name']=$this-&gt;input-&gt;post('bo_name');
         $data['section']=$this-&gt;input-&gt;post('section');
         $data['publish']=$this-&gt;input-&gt;post('publish');
         $data['author']=$this-&gt;input-&gt;post('author');
         $data['result1'] = '';
         $data['result2'] = '';
         $data['result3'] = '';
         $data['result4'] = '';
         if($data['bo_name'] == NULL and $data['section']== NULL and $data['publish']==NULL and $data['author']== NULL){
              $this-&gt;search_form();
         }else{
              if(isset($data['bo_name']) and $data['bo_name']!= NULL)
              {
                 $data['result1'] = $this-&gt;search-&gt;search_name();
  }
             if(isset($data['section']) and $data['section'] != NULL)
              {
                 $data['result2']=$this-&gt;search-&gt;search_all();
              }
              if(isset($data['publish']) and $data['publish'] != NULL)
              {
                 $data['result3']=$this-&gt;search-&gt;search_all();
              }
              if(isset($data['author']) and $data['author']!= NULL)
              {
                 $data['result4']=$this-&gt;search-&gt;search_all();
              }
              $data['no_results'] = '';
              if(! $data['result1'] &amp;&amp;  !$data['result2'] &amp;&amp;  !$data['result3'] &amp;&amp;  !$data['result4']){
                 $data['no_results'] = TRUE;
              }else{
                  $data['no_results'] = FALSE;
              }
              $this-&gt;view('search/site/search_result',$data);
          }
      }
  }
  
  /* End of file dashboard.php */
  </code></pre>