using implode for array inside mysql where in clause

后端 未结 2 1549
醉话见心
醉话见心 2021-01-23 04:41

im trying to use array for mysql where in clause

$result= $myDB->query(\"SELECT sum(total) as total FROM \".$myDB->prefix(\"mydata\").\" WHERE categoryname         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 05:42

    I did something similar a while ago using array_map, hope it helps:

    $args = array_map(function($a) {
        return sprintf("'%s'", $a);
    }, $args);
    
    $args = join(",", $args);
    

    The above code will iterate over the array and modifies every single element to surround it with ''. Finally, I join the array with ,.

提交回复
热议问题