setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "ERROR : ".$e->getMessage(); } $term=$_GET["term"]; $stmt = $DBcon->prepare("SELECT * FROM students where studentname like '%".$term."%' order by studentname"); $stmt->execute(); $json=array(); while($row=$stmt->FETCH(PDO::FETCH_ASSOC)) { $json[]=array( 'value'=> $row["regno"], 'label'=>$row["studentname"]." - ".$row["regno"] ); } echo json_encode($json); ?>