Question

I have a search function with a joined table.

I have a table factories. In this table i search for factories. i also have a table called tags. in this table i have tags for specific factories. with a factory id.

But when i search on a factory it shows me the factory more then once. when i delete the tags it isn't shown more than once.

How do i force/limit to only show 1 of the same factory?

You can see what i mean when you just click on search at http://kees.een-site-bouwen.nl/home/search

My search method /model:

function get_search($match)
{
    $this->db->like('Bedrijfsnaam', $match);
    $this->db->or_like('Postcode', $match);
    $this->db->or_like('Plaats', $match);
    $this->db->or_like('Telefoonnummer', $match);
    $this->db->or_like('Email', $match);
    $this->db->or_like('Website', $match);
    $this->db->or_like('Profiel', $match);
    $this->db->or_like('Adres', $match);
    $this->db->or_like('tags.Tag', $match);
    $this->db->join('tags', 'bedrijven.idbedrijven = tags.idbedrijven');
    $query = $this->db->get('bedrijven');

    return $query->result();
}

My search method /controller:

    function searchresults()
    {
        $match = $this->input->post('search');
        $data['query'] = $this->bedrijven_model->get_search($match);
        $this->load->view('views/header');
        $this->load->view('views/searchresults', $data);
        $this->load->view('views/footer');
        $data['query'] = $this->bedrijven_model->bedrijven_tags();
    }
Was it helpful?

Solution

Try with group by like

$this->db->join('tags', 'bedrijven.idbedrijven = tags.idbedrijven');
$this->db->group_by('bedrijven.idbedrijven');
$query = $this->db->get('bedrijven');

then you can get the unique values

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top