我需要一个codeigniter多表搜索脚本,如果有人在这里提供我?

dw1jzc5e  于 2023-02-27  发布在  其他
关注(0)|答案(2)|浏览(98)

我需要一个codeigniter多表搜索脚本,如果有人在这里提供我?我需要从我的数据库多个表搜索数据。我有超过20个表在我的数据库。
我的数据库里有20多个表。我想用我的搜索表搜索新闻、事件、通知等。你能帮我吗?

fruv7luv

fruv7luv1#

试试这个:

public function search()
{
    $query = $this->input->get('q');

    // Search the news table
    $this->db->select('*');
    $this->db->from('news');
    $this->db->like('title', $query);
    $this->db->or_like('content', $query);
    $news_results = $this->db->get()->result_array();

    // Search the events table
    $this->db->select('*');
    $this->db->from('events');
    $this->db->like('title', $query);
    $this->db->or_like('description', $query);
    $events_results = $this->db->get()->result_array();

    // Search the notices table
    $this->db->select('*');
    $this->db->from('notices');
    $this->db->like('title', $query);
    $this->db->or_like('content', $query);
    $notices_results = $this->db->get()->result_array();

    // Combine the results and pass them to the view
    $data = array(
        'news_results' => $news_results,
        'events_results' => $events_results,
        'notices_results' => $notices_results,
    );
    $this->load->view('search_results', $data);
}
rta7y2nd

rta7y2nd2#

我认为您必须更详细地解释您希望如何搜索以及您希望如何显示结果。

相关问题