Home site:
[js]<input type="hidden" id="search" value="" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="select2-3.5.1/select2.js"></script>
<script>
$(document).ready(function() {
$("#search").select2({
placeholder: "Search for site id",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "getSiteNames.php?q=test",
dataType: 'json',
data: function (term, page) {
return {
q: term, // search term
page_limit: 10 // Kun je later gebruiken
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
console.log(data);
}
}
});
});
</script>[/js]
getSiteNames:
Die echo uiteraard even voor de checks..
Code:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link href="select2-3.5.1/select2.css" rel="stylesheet"/>
<link rel="STYLESHEET" href="GRIP.css" type="text/css">
</head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="select2-3.5.1/select2.js"></script>
<script>
$(document).ready(function() {
$("#search").select2({
placeholder: "Search for site id",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "getSiteNames.php?q=test",
dataType: 'json',
data: function (term, page) {
return {
q: term, // search term
page_limit: 10 // Kun je later gebruiken
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
console.log(data);
}
}
});
});
</script>[/js]
getSiteNames:
PHP:
$sql = "SELECT DISTINCT SiteId FROM Dim.Host WHERE SiteId IS NOT NULL AND SiteId LIKE '". $_GET["q"] ."%'";
//$sql = "SELECT DISTINCT name FROM db WHERE name IS NOT NULL AND name LIKE '". $_GET["q"] ."%'";
$stmt = sqlsrv_query( $link, $sql);
if( $stmt === false )
{
die( print_r( sqlsrv_errors(), true));
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
echo $row["name"];
}
?>
{"keyword" : "<?= $_GET['q'] ?>"}
Die echo uiteraard even voor de checks..