codeigniter - Sql statement with multi ANDs querying the same column -
i don't know if title of post appropriate. have following table
and array in php items, parsed_array
. want find supermarketids have items of parsed_array
.
for example, if parsed_array
contains [111,121,131]
want result 21
id of supermarket contains these items.
i tried that:
$this->db->select('supermarketid'); $this->db->from('productinsupermarket'); ($i=0; $i<sizeof($parsed_array); $i++) { $this->db->where('itemid', $parsed_array[$i]); } $query = $this->db->get(); return $query->result_array();
if there 1 item in parsed_array
result correct because above equal to
select supermarketid productinsupermarket itemid=parsed_array[0];
but if there more 1 items, lets two, equal
select supermarketid productinsupermarket itemid=parsed_array[0] , itemid=parsed_array[1];
which of course return empty table. idea how can solved?
you can use where_in
in codeigniter below,
if(count($parsed_array) > 0) { $this->db->where_in('itemid', $parsed_array); }
Comments
Post a Comment