开发者

select table record in database by multi id by php

开发者 https://www.devze.com 2023-03-13 14:43 出处:网络
i have a value that name is brands and like this : $brands = \"1,2,3,4,5,\";开发者_运维百科 i can convert this value to this :

i have a value that name is brands and like this :

$brands = "1,2,3,4,5,";开发者_运维百科

i can convert this value to this :

$brands = "1,2,3,4,5";

i want write source that select * from table where id = each of brands

for example :

select * from brands where (id='1' or id='2' or id='3' or id='4' or id='5');

1,2,3,4,5 is Variable and can changed for example can change to 1,2,9,4,5,8

how i can write this ? please help thanks


If you already have the ids comma delimited...

$query = '
   SELECT *
     FROM `brands`
    WHERE `id` IN (' . $brands . ')';

If not, use implode(',', $ids).

If your ids are from user input and not already made safe, use...

$ids = implode(',', array_map('intval', explode(',', $ids)));


"select * from brands where id in (".$brands.");"

0

精彩评论

暂无评论...
验证码 换一张
取 消