2016-03-05 56 views
1

我的項目有問題。
我使用笨和REST庫,數據表jQuery插件在特定json中獲取mysql結果

我的表

Table `order` 

+----+----------+-------------+---------------------+---------+-------+ 
| id | table_id | waiter_name | date_time   | status | total | 
+----+----------+-------------+---------------------+---------+-------+ 
| 1 | Table 1 | Waiter 1 | 2016-03-03 12:44:27 | Pending | 1500 | 
+----+----------+-------------+---------------------+---------+-------+ 

table `orderitems` 

+----+----------+-------------+----------+ 
| id | order_id | food_item | item_qty | 
+----+----------+-------------+----------+ 
| 1 | 1  | Chicken Fry |  2 | 
| 2 | 1  | Beef  |  1 | 
+----+----------+-------------+----------+ 

table `foodinfo` 
+----+----------------+-----------+-----------+----------+ 
| id | food_item  | status | category | price | 
+----+----------------+-----------+-----------+----------+ 
| 1 | Chicken Fry | Available | Meat  |  600 | 
| 2 | Beef   | Available | Meat  |  300 | 
+----+----------------+-----------+-----------+----------+ 

我的夢想的DataTable

ID TABLE NAME WAITER NAME DATE AND TIME  FOODS   STATUS TOTAL 
1 Table 1  Waiter 1 1016-03-03 12:44:24 Chicken Fry-2 Pending 1500 
               Beef  -2 

我當前的查詢

$this->db->select('orderitems.*, order.*'); 
$this->db->from('order'); 
$this->db->from('orderitems'); 
$data = $this->db->get()->result_array(); 
$this->response($data); 

和JSON

[ 
    { 
    "id": "1", 
    "order_id": "1", 
    "food_item": "Chicken Fry", 
    "item_qty": "2", 
    "table_id": "Table 1", 
    "waiter_name": "Waiter 1", 
    "date_time": "2016-03-03 12:44:27", 
    "status": "Pending", 
    "total": "1500" 
    }, 
    { 
    "id": "1", 
    "order_id": "1", 
    "food_item": "Beef", 
    "item_qty": "2", 
    "table_id": "Table 1", 
    "waiter_name": "Waiter 1", 
    "date_time": "2016-03-03 12:44:27", 
    "status": "Pending", 
    "total": "1500" 
    } 
] 

如何使用json和datatable訪問此數據表?
codeigniter查詢生成器或mysql查詢。

回答

0

將數組返回給json對象。 json_decode或json_encode 對不起,但您的問題可能並不清楚。

+0

需要編寫一個從3個不同的sql表中返回數據的sql語句。 –

+0

你可以試試sql(鏈接查詢)。 – sun