Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

I have an array variable like this

$variable[] = $data['master_software_capability_id'];

How to use this array variable in SQL query

Is this the right way ?

SELECT * FROM software_capability where software_capability_id IN ($variable);
share|improve this question

marked as duplicate by Shankar Damodaran, Rikesh, Liath, giammin, Sheridan Mar 14 '14 at 8:52

This question was marked as an exact duplicate of an existing question.

up vote 0 down vote accepted

You need to implode the array to comma separated string

$variables_imploded = implode(",",$variable);

"SELECT * 
FROM software_capability 
where software_capability_id IN 
(".$variables_imploded.")";
share|improve this answer
    
Thanks abhik its working. – Senthilkumar Mar 14 '14 at 7:08
    
You are most welcome !! – Abhik Chakraborty Mar 14 '14 at 7:08
    
@Senthilkumar please accept this answer as accepted so it will be marked as solved – Dimag Kharab Mar 14 '14 at 7:14

use JOIN or IMPLODE

$variables_joins = join(',',$variable);  

SELECT * FROM software_capability where software_capability_id IN ($variables_joins);
share|improve this answer

You can implode the array first.. like implode(',',$variable)

"SELECT * FROM software_capability where software_capability_id IN (" . implode(',',$variable)  . ")"
share|improve this answer
    
Thanks Edd A. its working – Senthilkumar Mar 14 '14 at 7:08
    
Great.. Happy to help! – Eddie Who Mar 14 '14 at 7:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.