How to use php array with sql IN operator?

后端 未结 13 1763
北恋
北恋 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 06:47

    All the people here are proposing the same thing but i got a warning in WordPress because of a simple error. You need to add commas to your imploded string. To be precise something like this.

    $query = "SELECT *FROM table Where comp_id IN ( '" . implode( "', '", $sanitized_brands ) . "' )";
    

    Hoping it helps someone like me. :)

提交回复
热议问题