Welcome Guest, Not a member yet? Register   Sign In
Arrays in $this->db->like() don't work.
#1

[eluser]Joshee[/eluser]
Code:
$like = array(
    'date' => $this->uri->segment(3),
    'date' => $this->uri->segment(4)
);
$this->db->like($like);

It works, but it only grabs the database items where the 'date' field is LIKE $this->uri->segment(4). It doesn't grab the database items where the 'date' field is LIKE $this->uri->segment(3) AND the 'date' field is LIKE $this->uri->segment(4).

Basically it's not getting the database items where the 'date' field is LIKE both of the array items I set.

But if I make the code:
Code:
$this->db->like('date', $this->uri->segment(3);
$this->db->like('date', $this->uri->segment(4);

It grabs the datebase items where the 'date' field is LIKE both of the values.

If that makes sense I would like to know if there is a way to fix it.

Thanks.
#2

[eluser]ChrisMiller[/eluser]
From the sounds of it you are using the wrong fuctin for this you should be using $this->db-like() and also $this->db->or_like(). Sounds like your trying to find dates like Date A -OR- Date B

so it should look like...
Code:
$this->db->like('date', $this->uri->segment(3));
$this->db->or_like('date', $this->uri->segment(4));
#3

[eluser]InsiteFX[/eluser]
Thats because you have 2 date keys in your array all keys have to be different!

InsiteFX
#4

[eluser]Cristian Gilè[/eluser]
Code:
$like = array(
    'date' => $this->uri->segment(3),
    'date' => $this->uri->segment(4)
);

The size of the $like array is 1 because the two elements have the same key so the value of the first element is overwritten by the value of the second element.


Cristian Gilè
#5

[eluser]Joshee[/eluser]
[quote author="Cristian Gilè" date="1297748813"]
Code:
$like = array(
    'date' => $this->uri->segment(3),
    'date' => $this->uri->segment(4)
);

The size of the $like array is 1 because the two elements have the same key so the value of the first element is overwritten by the value of the second element.


Cristian Gilè[/quote]

Duh! I didn't even think of that >_>

So how would I go about doing what I am trying to do without having to type $this->db->like() two separate times?
#6

[eluser]InsiteFX[/eluser]
Rename one of your array elements from date to say date2. Also do not forget to update your database table field.

InsiteFX
#7

[eluser]Cristian Gilè[/eluser]
[quote author="InsiteFX" date="1297757941"]Rename one of your array elements from date to say date2. Also do not forget to update your database table field.

InsiteFX[/quote]

I think that Joshee wants to check the date only on one field (date). In this case you can use the ChrisMiller solution:
Code:
$this->db->like('date', $this->uri->segment(3));
$this->db->or_like('date', $this->uri->segment(4));


Cristian Gilè
#8

[eluser]Joshee[/eluser]
Nevermind guys, I changed my method of getting the database items so it doesn't matter anymore.




Theme © iAndrew 2016 - Forum software by © MyBB