How to use php array with sql IN operator?

后端 未结 13 1688
北恋
北恋 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:10

    You need to convert the array to a string for use in the query:

    $list = implode(',', $arr);
    

    Then it can be used in the IN clause:

    SELECT * from table Where comp_id IN ($list)
    
    0 讨论(0)
提交回复
热议问题