J
J
jack iakovenko2020-12-07 11:46:02
CodeIgniter
jack iakovenko, 2020-12-07 11:46:02

Implementation of a search on the site?

hello everyone, I hope someone can help and ask the question correctly,
so I created a site for watching movies on the php and codeigniter training course
and now I want to implement a search on the site so that I can search all database tables (the author of the video course has only one table with films and therefore I'm doing his lesson looking only for movies and I have 3 tables in the database "movie" "serial" "animation")
here is the code itself:
model:

<?php

class Search_model extends CI_Model {

    public function search($q) {
        $array_search = array(
            'name' => $q,
            'descriptions' => $q
        );

        $query = $this->db
            ->or_like($array_search)
            ->limit(100)
            ->get('movie');

        return $query->result_array();

        
    }

}


controller:
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Search extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->data['title'] = "Search";

        $this->load->model('search_model');
        $this->data['search_result'] = array();

        if($this->input->get('q_search')) {
            $this->data['search_result'] = $this->search_model->search($this->input->get('q_search'));
        }


        $this->load->view('templates/header', $this->data);
        $this->load->view('search', $this->data);
        $this->load->view('templates/footer');
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lykasov, 2020-12-07
@lykasov-aleksandr

Search each table individually and return the combined result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question