我正在尝试集成以下代码:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
Please enter your Suburb:
<input type="text" name="location_input" id="location_input">
Tutor:<select name="locations" id="locations">
</select>
<script>
$("#location_input").keyup(function(){
const location = $("#location_input").val();
$("#locations").html(''); //reset dropdown
// do ajax call to get locations
$.ajax({
url: 'search.php', //replace this with your route of the search function
data: {location}, //pass location as body data
success: function(data) {
let res = JSON.parse(data);
res.forEach(function(el) { //loop over the json response
let option = `<option id=${el.id} value=${el.name}>${el.name}</option>`
$("#locations").append(option); //append locations to select dropdown
});
},
error: function(err) { //error functions
console.log(err);
alert("Error")
}
});
});
</script>
</body>
</html>
Search.php:
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// echo "Connected successfully";
// print_r($_GET["location"]);
$location = $_GET["location"];
$result = $conn->query("select id, name, Location_tags from tutor_location where Location_tags LIKE '%". $location ."%'");
$locations = [];
while ($row = $result->fetch_assoc()) {
$locations[] = $row;
// echo $row["Name"];
}
echo json_encode($locations);
?>
进入我的easy!appointments模块,供用户选择提供商时使用。我希望用户输入其郊区,并且必须根据该位置显示提供商。在数据库中,我有一个名为location_tags
的字段,提供商在该字段中指定了他想去的郊区。
我要集成的代码在这里:
<div class="form-group" id="selectprovider">
<label for="select-provider">
<strong><?= lang('select_provider') ?></strong>
</label>
<select id="select-provider" class="col-xs-12 col-sm-4 form-control"></select>
</div>
这是由Alex Tselegidis制造的Easy!appointments模块 我该如何整合呢? Link to Easy!appointments