Passing an array to a query using a WHERE clause

后端 未结 18 1048
情歌与酒
情歌与酒 2020-11-21 09:03

Given an array of ids $galleries = array(1,2,5) I want to have a SQL query that uses the values of the array in its WHERE clause like:



        
18条回答
  •  悲哀的现实
    2020-11-21 09:32

    Use:

    select id from galleries where id in (1, 2, 5);
    

    A simple for each loop will work.

    Flavius/AvatarKava's way is better, but make sure that none of the array values contain commas.

提交回复
热议问题