Reputation: 31
$sql='SELECT * FROM PRODUCTS WHERE CATEGORY=array['0'] && CATEGORY=array['1'] && CATEGORY=array['2']';
my problem is array size was dependent sometimes it's count was 10 and some times it was 1. if it was 10 i have to write the in query up to 10 times. how to over come this. finally i'm using codeigniter in that how to write this query.
Upvotes: 0
Views: 106
Reputation: 1020
You have to query like that
$this->db->where_in('CATEGORY', $array);
$executequery = $this->db->get('PRODUCTS');
Upvotes: 0
Reputation: 3329
Try to format your query like this
$this->db->select('*');
$this->db->where_in('CATEGORY', $array);
$query = $this->db->get('mytable');
Upvotes: 1
Reputation: 1333
This is an example in CI
$names = array('Frank', 'Todd', 'James');
$this->db->where_in('username', $names);
Upvotes: 0
Reputation: 8838
try this code:
$cat_ids = implode(",",$array);
$sql = "SELECT * FROM PRODUCTS WHERE CATEGORY in (".$cat_ids.")";
Upvotes: 0