php - laravel 4.2 从 mysql 表中检索数据

标签 php mysql laravel-4

对于我的项目,我需要根据表中列出的 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" ."&deg"."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" ."&deg"."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" ."&deg"."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" ."&deg"."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" ."&deg"."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"."&deg"."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"."&deg"."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"."&deg"."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"."&deg"."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" ."&nbsp"."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" ."&deg"."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/

相关文章:

javascript - 从 CSS 中删除包含对外部文件的引用的行

php - php中如何对评论的评论进行整理

python - Django ORM 是否将删除的字段映射到 sql where 子句中的其他字段之前?

google-chrome - 浏览器关闭时 Laravel 过期 session 在 Chrome 中不起作用

php - Laravel 查询生成器,调用 count() 时使用自定义选择

php - 如何通过 laravel eloquent 模型连接三个表

php - 在 AJAX 中显示数据库数据的错误位置

mysql:从另一个表中选择行作为列

php - 我如何比较两个数组并将唯一记录添加到表中

php - Laravel Sqlcommand 无法检索结果