对于我的项目,我需要根据表中列出的 command 列和 system_id 和 current_value 从 mysql 表中获取温度。
我将值传递给 .blade.php 并尝试在我的网站上显示这些值。
在我的 BuildingController.php 中我有以下功能
public static function furnaceMap($building_id, $system_id)
{
$data['thisBldg'] = Building::find($building_id);
$data['thisSystem'] = System::find($system_id);
$data['boiler'] = 'boiler.jpg';
$currentData = DeviceDataCurrent::where('system_id', $system_id)
->where('command', '1') //i am only getting command 1 values
->orderby('id','ASC','command','ASC')
//->take(100)
->get();
$currentData = DeviceDataCurrent::where('system_id', $system_id);
$currentData->whereIn('command', function($subquery)
{
$subquery->from('device_types')
->select('command')
->where('function', 'Temperature');
});
$currentData =$currentData
->orderby('id','ASC','command','ASC')
->get();
//dd($currentData -> toArray());
$data['apartments'] = [
['x-pos'=>"100", 'y-pos'=>"80" , 'state'=>"success", 'name'=>"Apt1" ,'tag'=>"Temperature:", 'temp'=>"76" ."°"."F", 'status'=>"On" , 'high'=>"80" , 'low'=>"70" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"250", 'y-pos'=>"80" , 'state'=>"warning", 'name'=>"Apt2" ,'tag'=>"Temperature:", 'temp'=>"77" ."°"."F", 'status'=>"On" , 'high'=>"80" , 'low'=>"70" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"400", 'y-pos'=>"80" , 'state'=>"success", 'name'=>"Apt3" ,'tag'=>"Temperature:", 'temp'=>"55" ."°"."F", 'status'=>"Off", 'high'=>"80" , 'low'=>"45" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"550", 'y-pos'=>"80" , 'state'=>"success", 'name'=>"Apt4" ,'tag'=>"Temperature:", 'temp'=>"67" ."°"."F", 'status'=>"On" , 'high'=>"85" , 'low'=>"60" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"700", 'y-pos'=>"80" , 'state'=>"success", 'name'=>"Apt5" ,'tag'=>"Temperature:", 'temp'=>"67" ."°"."F", 'status'=>"On" , 'high'=>"85" , 'low'=>"60" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"100", 'y-pos'=>"335", 'state'=>"success", 'name'=>"DHW" ,'tag'=>"Temperature:", 'temp'=>"113"."°"."F", 'status'=>"Off", 'high'=>"110", 'low'=>"90" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"215", 'y-pos'=>"335", 'state'=>"success", 'name'=>"CHW" ,'tag'=>"Temperature:", 'temp'=>"132"."°"."F", 'status'=>"On" , 'high'=>"135", 'low'=>"125", 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"390", 'y-pos'=>"270", 'state'=>"warning", 'name'=>"STACK" ,'tag'=>"Temperature:", 'temp'=>"675"."°"."F", 'status'=>"On" , 'high'=>"680", 'low'=>"660", 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"700", 'y-pos'=>"250", 'state'=>"warning", 'name'=>"RETURN" ,'tag'=>"Temperature:", 'temp'=>"125"."°"."F", 'status'=>"On" , 'high'=>"135", 'low'=>"110", 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"650", 'y-pos'=>"435", 'state'=>"success", 'name'=>"Make-up Water",'tag'=>"Water Amount:",'temp'=>"7" . "gal", 'status'=>"On" , 'high'=>"25" , 'low'=>"10" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"550", 'y-pos'=>"225", 'state'=>"success", 'name'=>"Steam" ,'tag'=>"Pressure:" , 'temp'=>"12" ." "."lb",'status'=>"On" , 'high'=>"25" , 'low'=>"10" , 'location'=>"loc", 'systemID'=>"xxxxxx" ],
['x-pos'=>"455", 'y-pos'=>"435", 'state'=>"warning", 'name'=>"AQS" ,'tag'=>"Temperature:", 'temp'=>"18" ."°"."F", 'status'=>"On" , 'high'=>"25" , 'low'=>"10" , 'location'=>"loc", 'systemID'=>"xxxxxx" ]
];
return View::make('buildings.furnace', $data);
}
基于command列和system_id列我需要分发数据。例如,如果 system_id 是 60,command 是 1,那么 current_value 就是我的 apt1 的值,如果 system_id 是 61,command 是 1,那么 current_value 是我的 apt2 的值,依此类推。我已经做到了这一点,似乎我真的不知道下一步该怎么做才能将数据传递给临时工。 如果有人能帮助我解决这个问题,我会很高兴。
最佳答案
关于php - laravel 4.2 从 mysql 表中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30333713/