Guest User

Untitled

a guest
Nov 10th, 2012
474
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     global $dbh;
  2.  
  3.     $countries = array();
  4.     $term = '';
  5.  
  6.     if (isset($_GET['term'])) {
  7.         $term = trim(strip_tags($_GET['term']));
  8.     }
  9.  
  10.     if (isset($term)) {
  11.         $stmt = $dbh->prepare("SELECT name FROM countries WHERE name LIKE CONCAT('%', :term, '%') ORDER BY name ASC");
  12.         $stmt->bindParam(':term', $term, PDO::PARAM_STR);
  13.         if ($stmt->execute()) {
  14.             while ($row = $stmt->fetch()) {
  15.                 $countries[] = $row['name'];
  16.             }
  17.         }
  18.     }
  19.  
  20.     echo json_encode($countries);
RAW Paste Data