Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Connection vars here for example only. Consider a more secure method. */
- $dbhost = 'xxx.db.xxx.xxx.com';
- $dbuser = 'user';
- $dbpass = 'password';
- $dbname = 'name';
- try {
- $conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
- }
- catch(PDOException $e) {
- echo $e->getMessage();
- }
- $return_arr = array();
- // Do Prepared Query
- $query = $conn->prepare("SELECT booth,exhibitor FROM exhibitors WHERE exhibitor LIKE :search LIMIT 40");
- // Add a wildcard search to the search variable
- $query->execute(array(':search'=>"%".$search."%"));
- // Do a quick fetchall on the results
- $list = $query->fetchall(PDO::FETCH_ASSOC);
- // Make sure we have a result
- if(count($list) > 0){
- foreach ($list as $key => $value) {
- $data[] = array('id' => $value['booth'], 'text' => $value['exhibitor']);
- }
- } else {
- $data[] = array('id' => '0', 'text' => 'No Products Found');
- }
- // return the result in json
- echo json_encode($data);
- $( ".webform-component--exhibitor-information--exhibitor-select" ).select2({
- placeholder: "Select Exhibitor",
- allowClear: true,
- ajax: {
- url: "https://example.com/dbase.php",
- dataType: 'json',
- delay: 250,
- data: function (params) {
- return {
- q: params.term // search term
- };
- },
- processResults: function (data) {
- // parse the results into the format expected by Select2.
- // since we are using custom formatting functions we do not need to
- // alter the remote JSON data
- return {
- results: data
- };
- },
- cache: true
- },
- minimumInputLength: 2
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement