efter din HTML-kod lägg till
<div class="showsearch"></div>
js-kod
$(document).ready(function(){
$('#drop2').on('change',function(){
var fname = $(this).val();
// rename your file which include $fname with get_search_data.php
if(fname !== ""){
$.post('get_search_data.php',{fname: fname},function(data){
$('.showsearch').html(data);
});
}
});
});
- efter den koden bör den visa $row['fname'] för att showearch div
- du måste inkludera("connection.php"); i get_search_data.php
get_search_data.php
<?php
include("connection.php");
if(isset($_POST['fname'])){
$fname = mysqli_real_escape_string($con, $_POST['fname']);
}
$sql1 = 'SELECT * FROM office WHERE fname LIKE "%'.$fname.'%"';
$result = mysqli_query($con, $sql1);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result)) {
echo $row["fname"]; // this data should appear in showsearch div
}
} else {
echo "0 results";
}
mysqli_close($con);
?>