function get_book_control() { if (filter_input(INPUT_GET, 'id')) { $obj = new books(); $id = sanitize_string(filter_input(INPUT_GET, 'id')); if ($obj->get_book($id)) { echo '{"result":1, "books":['; $row = $obj->fetch(); while ($row) { echo json_encode($row); if ($row = $obj->fetch()) { echo ','; } } echo ']}'; } else { echo '{"result":0,"message": "Book not found"}'; } } }