0

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);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Senthilkumar
  • 100
  • 3
  • 16

2 Answers2

2

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.")";
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
1

use JOIN or IMPLODE

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

SELECT * FROM software_capability where software_capability_id IN ($variables_joins);
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45