我有两个数组
temp[]
time[]
例如,如果我的数组中有这样的数据
temp time
[0] 80 45
[1] 70 50
[2] 85 65
[3] 90 30
我想根据这两个数组参数查询数据 像 (select * from MyTable where (temperature = 80 and time = 45 ))for the next (select * from MyTable where (temperature = 70 and time = 50 )) 等等
我正在做这样的事情
$mix=MyTable::whereIN('temperature', $temp)
->whereIN('time', $time)->where('category',$cat)
->get();
但它给我的输出是这两个参数的组合。不完全是从数组 0 开始...
我希望我能正确解释我的问题..
我试过了..
$result=Ergebnisse::where('name_id', $nam)->where('geometrie_id', $geo)->get();
foreach ($result as $key => $res) {
$mix=Ergebnisse::where('temperatur', $res->temperatur)
->where('zeit', $res->zeit)->groupBy('katogorie_id')
->get();
}
当我 dd($mix) 它只显示一个结果。但根据我的数据库,它应该显示不止一个
最佳答案
whereIn()
在这里不起作用。做这样的事情:
$data = MyTable::where('category', $cat)
->where(function($q) use($array) {
foreach ($array as $item) {
$q->orWhere(function($q) use($item) {
$q->where('temperature', $item['temp'])
->where('time', $item['time']);
}
}
})->get();
关于php - WhereIn Eloquent 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43093466/