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
  • 66,874
  • 43
  • 94
  • 124
Senthilkumar
  • 100
  • 3
  • 16

2 Answers2

1

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
  • 43,914
  • 5
  • 48
  • 61
0

use JOIN or IMPLODE

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

SELECT * FROM software_capability where software_capability_id IN ($variables_joins);
Dimag Kharab
  • 4,391
  • 1
  • 20
  • 44