简体   繁体   中英

Using where_in in delete or select query codeigniter

I am trying to use where_in in codeigniter delete function . I am imploding the array values which are integers received from the view. But since i need to pass them into where_in i implode it as :

implode(",",$delete_ids); //output: 12,13

But when i pass it to the query it displays as

SELECT * FROM (`table`) WHERE `id` IN ('12,13');

I also tried using

implode("','",$delete_ids); // output:12','13

but when i pass it to the query function it shows :

SELECT * FROM (`table`) WHERE `id` IN ('12\',\'13') 

not putting any extra parameters in it .

Please help me with a solution for this...Thank You

您应该将数组传递给where_in而不要implode(....),您的代码将如下所示:

$db->where_in('your_field', $delete_ids);

By codeigniter database documentation , you can simply use where_in() function. You can use this:

$this->db->where_in('id', $delete_ids);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM