所以,我正在使用 php、jquery 和 mysql 进行 PHP 实时搜索。尽管数据库中存在数据,但正在搜索的数据未显示在我的页面中。
rowCount() 显示正确的总行数,但页面未显示所有行。
这是我的 php 代码
<?php
if(isset($_POST['keyword'])){
$key = $_POST['keyword'];
$findPerusahaan = "SELECT * FROM perusahaan_instansi WHERE badan_hukum LIKE '%$key%' OR merek LIKE '%$key%' ";
$stmt = $conn->prepare($findPerusahaan);
$stmt->execute();
$data =$stmt->fetch();
foreach($stmt as $row){
echo $row['badan_hukum']."<br>";
}
//print_r($stmt);
echo $stmt->rowCount();
}
?>
这是页面
<input onkeyup="myFunction()" type="text" id="myInput" class="form-control"
id="perusahaan" name="perusahaan" placeholder="PT....." required>
<div id="perusahaan"></div>
<script>
function myFunction() {
console.log($('#myInput').val());
var keyword = $('#myInput').val();
$.ajax({
type:'POST',
url: 'index.php?modul=form_submit&action=perusahaan',
data: {'keyword': keyword },
success:function(data){
console.log(data);
$('#perusahaan').empty();
$('#perusahaan').append(data);
}
});
}
</script>
这是结果,感谢您的帮助
呼如林
ibeautiful