function search() { include_once "faculty.php"; $obj = new Faculty(); $txt = $_REQUEST['txt']; if (!$obj->search($txt)) { echo '{"result":0, "message":"Searched Item does not exists"}'; return; } $row = $obj->fetch(); echo '{"result":1,"faculties":['; while ($row) { echo json_encode($row); $row = $obj->fetch(); if ($row) { echo ","; } } echo "]}"; }