Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

codeigniter query  returning too many results

Posted on 2016-10-29
3
Medium Priority
?
93 Views
Last Modified: 2016-10-29
I've created a codeigniter query for a search function using the query builder class and it returns too many results. How could I adjust it to get a more specific result set?

My codeigniter query (shortened version):

function get_print_search() {
$match = $this->input->post('search');
$this->db->like('ExhibitionE','Provenance Online');  
$this->db->like('DepartmentE','Jewish Art');
$this->db->like('TitleE',$match);
$this->db->or_like('ArtistE',$match);
$this->db->or_like('ObjectNameE',$match);                  
$query = $this->db->get('combh');
return $query->result();
}

The type of sql query I would like to use:
SELECT TitleE, ArtistE, ObjectNameE FROM combh WHERE (ExhibitionE Like 'Provenance Online' AND DepartmentE Like 'Jewish Art' ) AND (TitleE Like $match OR ArtistE Like $match OR ObjectNameE Like $match)

There seems to be some confusion in the codeigniter query about where the parenthesis separate the query parts in the sql query. The current codeigniter query  returns all the TitleE, ArtistE and ObjectNameE results from  'Provenance Online' and I would like to get just the  'Provenance Online'  results from 'Jewish Art'.
Thanks for any assistance.
0
Comment
Question by:avir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41865087
Can you give me few rows and the expected output?
0
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 41865102
Yeah - CodeIgniter doesn't get on with adding parenthesis, so you'll need to build them manually:

$this->db
    ->select("TitleE, ArtistE, ObjectNameE")
    ->from("combh")
    ->like("ExhibitionE","Provenance Online")
    ->like("DepartmentE","Jewish Art")
    ->where("(TitleE LIKE '%$match%' OR ArtistE LIKE '%$match%' OR ObjectNameE LIKE '%$match%')");

return $this->db->get()->result();

Open in new window

1
 

Author Closing Comment

by:avir
ID: 41865112
Worked great. Thanks.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
The viewer will learn how to count occurrences of each item in an array.

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question