2016-09-16 58 views
0

我有一個像下面兩個表創建JSON數據:如何從兩個表

表:問題

id ~~ quest 
——————————————— 
01 ~~ where is the fruit..? 
02 ~~ what is the most popular name in the world..? 

表:choice_answer

idq ~~ choice 
——————————————— 
01 ~~ mango 
01 ~~ car 
01 ~~ bottle 
02 ~~ Jhon 
02 ~~ Nina 
02 ~~ Michael 

,其結果是:

1. "where is the fruit..?" 
    * mango 
    * car 
    * bottle 

2. "what is the most popular name in the world..?" 
    * Jhon 
    * Nina 
    * Michael 

如何使數據JSON ON PH P CodeIgniter? 以及如何使用上面的結果在IONIC上使用ng-repeat創建視圖?

+0

第一個問題的數組,然後把循環的問題和ans在這個循環中查詢,然後傳遞你的數組在$ this-> output-> set_content_type('application/json') - > set_output(json_encode($ your_array));' –

回答

0

您可以從兩個表中獲取數據,並將兩個表的數據作爲兩個不同的數組,然後使用json_encode()並將這個函數與兩個名稱的數組一起提供。像:

$q = array("q1", "q2"); 
$a = array("a1", "a2); 
echo json_encode(["question" => $q, "content" => $a]); 
0

我遇到過這樣的問題。離子只是不接受正常的迴應JSON。

如果您使用的是IONIC,我建議您使用this的Rest API。只需按照項目中給出的示例。