0
$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.

0

4 Answers 4

1

Try to format your query like this

$this->db->select('*');
$this->db->where_in('CATEGORY', $array);
$query = $this->db->get('mytable');
Sign up to request clarification or add additional context in comments.

Comments

0

try this code:

$cat_ids = implode(",",$array);

$sql = "SELECT * FROM PRODUCTS WHERE CATEGORY in (".$cat_ids.")";

Comments

0

This is an example in CI

$names = array('Frank', 'Todd', 'James');
$this->db->where_in('username', $names);

Comments

0

You have to query like that

$this->db->where_in('CATEGORY', $array);
$executequery = $this->db->get('PRODUCTS');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.