I’m working with an ad booking system, not built by myself. For each row in the ads table, there can be multiple sizes. Each size is a reference ID to another table. That’s fine.
But it’s stored like this (when I write space, that’s an actual space):
1(space)(space)(space)12(space)
1(space)(space)(space)(space)(space)
2(space)(space)25(space)1
Looks like this:
1 12
1
2 25 1
So, of course, when I do a query like this:
$this->db->get_where('online_ads', array('submitted >=' => '1314887098', 'submitted <=' => '1317673118', 'size' => '1'));
I get anything with a 1 in it. I tried this:
$this->db->like('size', '1')->get_where('online_ads', array('submitted >=' => '1314887098', 'submitted <=' => '1317673118'));
But it still doesn’t give me accurate results. I also tried FIND_IN_SET but that only works with commas.
How can I find out how many 1s, how many 2s, how many 12s, etc. there are stored without it giving me anything with a 1 in it or a 2?
I think you’ll have to use more advanced pattern matching, like regexp. If you want only things starting with “1 “, something like
RLIKE "^1 "should work, I think.