0

I write:

$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);
        });

but with this code I get only first result [0] ...

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

How to make while loop on results to get all data from results?

2
  • What framework are you using ? Commented Dec 1, 2014 at 17:49
  • You're not looping anything. And you should pass in $user_id instead of using global. Commented Dec 1, 2014 at 17:51

1 Answer 1

1
foreach($result as $row){
echo $row["id"];
 //-- and so on
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.