php 5.4 - php -- fetching data from a table and matching with another table to get data -
i have 2 tables; dashboard_map_items , device_data_current. in dashboard_map_items have 2 field, id , command , in device_data_current have 3 field id, commands, current_value. based on id , commands in dashboard_map_items need current_data device_data_current.
now dont know start. before able hard-code id , command , fetch current_data device_data_current not working me anymore, because id , commands changed in future.
$currentvalues = devicedatacurrent::where('map_id', 1) ->where('system_id', $system_id) ->where('command', 1)->where('id', 64) ->orderby('datetime', 'desc')->take(1)->get();
this doing data. if using laravel 4.2 framework dont know has laravel. pure php. appreciated.
i found solution
$currentvalues = dashboardmapitem::where('system_id', $system_id) ->select()->join('device_data_current', function($join){ $join->on('device_data_current.id', '=', 'dashboard_map_items.device_id'); $join->on('device_data_current.command', '=', 'dashboard_map_items.command'); }) ->get(); dd($currentvalues->toarray());
Comments
Post a Comment