加入mySQL表并为Ionic 2 App输出JSON

时间:2016-07-19 20:45:43

标签: mysql json

我正在尝试加入以下两个表示例;

{
"demo_one":[
    {"name":"Moby Dick", "position":"Whale", "phone":"1-403-651-4000"},
    {"name":"Jaws", "position":"Shark", "phone":"1-403-651-4000"}
],

"demo_two":[
    {"name":"Son of Moby Dick", "type":"Whale", "cell":"1-403-651-4000"},
    {"name":"Son of Jaws", "type":"Shark", "cell":"1-403-651-4000"}
]
}

这是我正在寻找的json结果

  SELECT SYMBOL, TRADE_DATE , LAST_10_DAYS 
  FROM FF_HISTORICAL_STOCK_PRICE 
  WHERE SYMBOL='ADI' 
  AND trade_date = (select MAX(TRADE_DATE)  FROM FF_HISTORICAL_STOCK_PRICE   )

我已经看到了一些关于堆栈溢出的例子,但我需要这个json输出用于我的Ionic 2 App。

1 个答案:

答案 0 :(得分:1)

这不需要加入,只需要两个单独的查询。他们的结果被放入JSON结果的不同属性中。

$result = array();
$query1 = $pdoconn->query("SELECT * FROM demo_one");
$result['demo_one'] = $query1->fetchAll(PDO::FETCH_ASSOC);
$query2 = $pdoconn->query("SELECT * FROM demo_two");
$result['demo_two'] = $query2->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);