getConnection(); $offlistread = new office($db); // query products $stmt = $offlistread->off_list_read(); $num = $stmt->rowCount(); // check if more than 0 record found if($num>0){ // products array $offlistread_arr=array(); $offlistread_arr["offlistrecords"]=array(); // retrieve our table contents // fetch() is faster than fetchAll() // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ // extract row // this will make $row['name'] to // just $name only extract($row); $offread_item=array( "brch_id" => $brch_id, "brch_name" => $brch_name ); array_push($offlistread_arr["offlistrecords"], $offread_item); } // set response code - 200 OK http_response_code(200); // show products data in json format echo json_encode($offlistread_arr); } ?>