Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:44:48+00:00 2026-06-02T12:44:48+00:00

I want to build advanced search script but I have this error with search_all

  • 0

I want to build advanced search script but I have this error with search_all function in the model

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

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

the model is

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->db->where('ne_id',$id);

    $result=$this->db->get('d_search');

    return $result->row();

    }
    //////////////frontend//////////////////////////////////////////////////////////

    function show_new($id)
    {

    $result=$this->db->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->row() ;

    }

    function generate_results($keyword,$row=0){
        $result1 = $this->db->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->db->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->db->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->result_array(),$result2->result_array(),$result3->result_array());

        return $results;

    }

    // get total number of users
    function getNumUsers($keyword)
    {
        $result1 = $this->db->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->num_rows();
        $result2 = $this->db->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->num_rows();
        $result3 = $this->db->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->num_rows();
        return $result1 + $result2 + $result3;
    }
    //////////////////////////////////end paging///////////////////

    function get_publishing()
    {
        $this->db->where('pub_state','1');
        $result=$this->db->get('d_publishing')->result_array();
        return $result;
    }

    function get_author()
    {
        $this->db->where('au_state','1');
        $result=$this->db->get('d_author')->result_array();
        return $result;
    }

    function get_section()
    {
        $this->db->where('sec_state','1');
        $result=$this->db->get('d_section')->result_array();
        return $result;
    }

    function search_name()
    {
        $bo_name=$_POST['bo_name'];
        $this->db->order_by("bo_ord","asc");
        $this->db->like('bo_name',$bo_name);
        return $this->db->get('d_book')->result_array();

    }


        function search_all() {
        $publish = $this->input->post('publish');
        $author = $this->input->post('author');
        $sec_name = $this->input->post('section');

        $sql = $this->db->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) > 0) {
       $sql .= "WHERE " . implode(" AND ", $searches);
        }
        $sql .= ';';


    }


}

this is controller

class Search extends front_end {
    var $temp;

    function __construct(){
       parent::__construct();
       $this->load->library('form_validation');
       //echo $this->input->post("keyboard");

    }

    public  function index()
    {
        $this->overview();
    }

    /**
     * This function display all  search
     * @param integer $row
     */
    public  function overview($row=0)
    {
        $this->form_validation->set_rules('keyword', 'كلمة البحث', 'trim|required|xss_clean|htmlspecialchars');
        $this->form_validation->run();
        $this->store_keyword();
        //echo $this->session->flashdata('keyword');
        if ($this->session->flashdata('keyword') != ''){
            $keyword=$this->session->flashdata('keyword');
            $this->generate_results($this->session->flashdata('keyword'),$row);
        }else{
        $this->generate_results($this->input->post("keyword"),$row);
        }
        //$this->session->set_flashdata('keyword', $this->input->post("keyword"));
        $data = $this->temp;

        //$this->session->keep_flashdata('keyword');
        $this->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->load->model('search/search_model','search');
        $this->load->library('pagination');
        $config['base_url'] = base_url().'search/search/overview/';
        $config['total_rows'] = $this->search->getNumUsers($keyword);
        $config['per_page'] = '20';
        $config['uri_segment'] = '4';
        $this->pagination->initialize($config);
        $data['page'] = $row;
        $data['results'] = $this->search->generate_results($keyword,$row);
        $data['total_rows'] = $this->search->getNumUsers($keyword);
        $data['links']=$this->pagination->create_links();
        $this->temp = $data;

    }

    /**
     * This function display detail of new
     * @param integer $id
     */
    public  function show($id)
    {
        $data['new']=$this->search->show_new($id);
        $count=$data['new']->ne_count_visit;
        $this->search->add_count($count,$id);
        $data['comments']=$this->search->show_comments($id);
        $this->view('site/new', $data);
    }

    /**
     * This function store keyword to use in search 
     */
    private  function store_keyword(){
        if($this->input->post("keyword")){
           $this->session->set_userdata('keyword', $this->input->post("keyword"));
       }
    }


    public  function search_form()
    {
        $this->load->model('search/search_model','search');
        $data['publish']=$this->search->get_publishing();
        $data['author']=$this->search->get_author();
        $data['section']=$this->search->get_section();
        $this->view('search/site/adv_search_form',$data);
    }

    public function search_adv()
    {
       $this->load->model('search/search_model','search');
       $data['bo_name']=$this->input->post('bo_name');
       $data['section']=$this->input->post('section');
       $data['publish']=$this->input->post('publish');
       $data['author']=$this->input->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->search_form();
       }else{
            if(isset($data['bo_name']) and $data['bo_name']!= NULL)
            {
               $data['result1'] = $this->search->search_name();
}
           if(isset($data['section']) and $data['section'] != NULL)
            {
               $data['result2']=$this->search->search_all();
            }
            if(isset($data['publish']) and $data['publish'] != NULL)
            {
               $data['result3']=$this->search->search_all();
            }
            if(isset($data['author']) and $data['author']!= NULL)
            {
               $data['result4']=$this->search->search_all();
            }
            $data['no_results'] = '';
            if(! $data['result1'] &&  !$data['result2'] &&  !$data['result3'] &&  !$data['result4']){
               $data['no_results'] = TRUE;
            }else{
                $data['no_results'] = FALSE;
            }
            $this->view('search/site/search_result',$data);
        }
    }
}

/* End of file dashboard.php */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:44:52+00:00Added an answer on June 2, 2026 at 12:44 pm

    $this->db->query() doesn’t store a query string for later use. It actually executes the query right away and return an object of CI_DB_mysql_result. You should build the query string before you call $this->db->query() and store it into a variable, then pass it into the method.

    $sql = "SELECT * FROM `d_book` ";
    $searches = array();
    if ($publish != 'choose')
    {
        $searches[] = "`bo_pub_id` = '__some_id__'";
    }
    
    if ($author != 'choose')
    {
        $searches[] = "`bo_au_id` = '__some_id__'";
    }
    
    if ($sec_name != 'choose')
    {
        $searches[] = "`bo_sec_id` = '__some_id__'";
    }
    
    if (count($searches) > 0) 
    {
        $sql .= "WHERE " . implode(" AND ", $searches);
    }
    
    $sql .= ';';
    $this->db->query($sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to build advanced search finder for my Candidate model. Lets imagine it
I want build a sketch pad app on iPhone, I assume that this type
I want to build my solution file using MSBuild but there is one issue.
I have an SQL search function built up as following: SELECT * FROM Table
I have a website build using PHP and HTML. If a user browses my
I want to perform an advanced query for the Task model (simplified versio: class
i want build a photography app with effects . e.g. old images with brown
I want to build an array of a list of state abbreviations, and since
I want to build a lightweight linux configuration to use for development. The first
I want to build a bot that asks someone a few simple questions and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.