我有一个ID值为[1,5,2,6,7 …]的数组,我需要在MySQL item_id IN(1,5,2,6,7 …)语句中使用该数组以仅选择在阵列中列出ID的行。如何将$ arrIDs转换为可插入SQL查询的内容?
EDIT-通话内容:
if(!IsNullOrEmptyString($_GET["view_playlist"])) { session_destroy(); } $id_list = implode(",", $_SESSION("playlist")); $sql = 'SELECT t.track_id, t.track_title, t.track_num, al.album_title, g.genre_name, a.artist_name, t.length, t.track_rating '. 'FROM track t, genre g, artist a, album al '. 'WHERE t.track_id IN('.$id_list.' AND t.genre = g.genre_id AND t.artist = a.artist_id AND t.album = al.album_id';
使用implode();
implode()
$ids = implode(',', $your_array);