2014-12-01 103 views
0

回应我写的:获得来自阵列

$app->get('/tasks', 'authenticate', function() { 
      global $user_id; 
      $response = array(); 
      $db = new DbHandler(); 

      // fetching all user tasks 
      $result = $db->getAllUserTasks($user_id); 

      $response["error"] = false; 
      $response["tasks"] = array(); 

      // looping through result and preparing tasks array 
      $response["error"] = false; 
       $response["id"] = $result["id"]; 
       $response["task"] = $result["task"]; 
       $response["status"] = $result["status"]; 
       $response["createdAt"] = $result["created_at"]; 
       echoRespnse(200, $response); 
     }); 

但是这个代码,我只得到第一个结果[0] ...

{ 
error: false 
tasks: [0] 
id: 2 
task: "Create something" 
status: 0 
createdAt: "2014-12-01 01:58:42" 
} 

如何让同时在结果循环获取所有数据从结果?

+0

您使用的是什么框架? – 2014-12-01 17:49:58

+0

苗条的框架... – LaraBeginer 2014-12-01 17:50:58

+0

你没有循环任何东西。你应该传入$ user_id而不是使用全局。 – 2014-12-01 17:51:50

回答

1
foreach($result as $row){ 
echo $row["id"]; 
//-- and so on 
} 
+0

我现在得到的只是:{ 错误:错误 任务:[0] } – LaraBeginer 2014-12-01 17:53:52