setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); #select all columns from the todos table $rows = $db->query("SELECT * FROM todos;"); header("Content-Type: application/json"); $output = array(); # loop through each row of data from the select # adding it to the output array foreach($rows as $row){ $task_num = $row["task_num"]; $output[$task_num] = array(); $output[$task_num]["name"] = $row["task_name"]; $output[$task_num]["due_date"] = $row["due_date"]; } #encode the output array as json print(json_encode($output)); ?>