Welcome Guest, Not a member yet? Register   Sign In
Combining where() and like()
#1

[eluser]nextexile[/eluser]
I'm structuring a query like so:

Code:
$this->db->where('id', $id);
foreach($makes as $make)
{
$this->db->or_like('make', $make);
}
$this->db->like('zip_codes_in_radius', $zip)

If I print it out, CI assembles it like so:

Code:
"SELECT * FROM (`submissions`) WHERE `id` = '12' AND `make` LIKE '%Chrysler%' OR `make` LIKE '%Dodge%' OR `make` LIKE '%Jeep%' OR `make` LIKE '%Ram%' AND `zip_codes_in_radius` LIKE '501%'"

The result I get makes me feel like this query is not considering the id. I want all three to be true, the id, the LIKE in make and LIKE in zip. But the result I get is often true to make and zip but not the id.
#2

[eluser]TheFuzzy0ne[/eluser]
Each row is uniquely identified by ID, why do you need to use LIKE as well? Surely you'll end up with a single result every time, which probably isn't what you want.
#3

[eluser]nextexile[/eluser]
[quote author="TheFuzzy0ne" date="1363599844"]Each row is uniquely identified by ID, why do you need to use LIKE as well? Surely you'll end up with a single result every time, which probably isn't what you want.[/quote]

I found a workaround for now but I was using it for validation. I pass the id in uri segment 3 so to prevent people from typing in a random id and getting the result I need to verify they have the right to see it.




Theme © iAndrew 2016 - Forum software by © MyBB