How to use php array with sql IN operator?

后端 未结 13 1788
北恋
北恋 2020-11-29 06:23

I have and array with two values and I want to use it with sql IN operator in select query.

Here is the structure of my table

id comp_id
1   2
2   3
         


        
13条回答
  •  孤街浪徒
    2020-11-29 07:06

    You need to actually convert your $arr to a string. The simplest way with what you're doing would be to use implode()

    $query = 'SELECT * from table Where comp_id IN (' . implode(',', $arr) . ')';
    

    Right now if you echo your query you'll see that rather than the array being in the IN statement, it will just be the word "Array"

提交回复
热议问题