当我想要内爆时,我使用$occu = implode(',',$_POST["occupation"]),它会发生内爆,结果就是1,2,4。
现在,当我在查询中使用$occu时,如下所示:
$total = DB::table('store')
->WhereIn('occupation_id',[$occu])
->get();然后,它只获取id 1,而不是2和4。
但是,如果我用这种方法:
$total = DB::table('store')
->WhereIn('occupation_id',[1,2,4])
->get();然后获取所有三个it。
因此,我想知道为什么基于变量的内爆第一个id,而不是另外两个。
发布于 2018-11-25 06:21:44
在Laravel中,我们需要为whereIn函数提供数组值。但您提供了分隔逗号的字符串。
你应该用这个代替
$arrVal = $_POST['ids'];
$items = DB::table('store')
->whereIn('field', $arrVal)
->get();上面是示例代码。请尝尝这个。
https://stackoverflow.com/questions/53465077
复制相似问题