1
我想創建一個搜索功能。這個頁面已經有一些細節,我從數據庫中檢索div。我想當我點擊搜索按鈕時,隱藏所有檢索到的細節並顯示搜索到的細節。我爲它使用了ajax。現在問題是當我點擊搜索按鈕時,先前檢索到的數據是隱藏的,但不會顯示爲搜索結果。通過php中的ajax顯示數據
<form action="../PHP/searchrmvvac.php" method="post">
<div class="search hidden-xs hidden-sm">
<input type="text" placeholder="Search" id="search" name="search">
</div>
<div>
<input type="button" value="Search" id="searchrmvcom" name="searchrmvcom">
<script>
$("#searchrmvcom").click(function() {
var comname=$('#search').val();
$.ajax({
type:"post",
url:"../PHP/searchrmvvac.php",
data:{comname:comname},
success:function (data3) {
$('#rmvcomdiv').hide();
$('#ela').html(data3)
}
});
});
</script>
</div>
</form>
searchrmvvac.php
<?php
session_start();
require('../PHP/dbconnection.php');
$output=$_POST['comname'];
$sql="select * from company where company_name='$output' and activation_code=1";
$res=mysqli_query($conn,$sql);
if(mysqli_num_rows($res)>0) {
echo '
while ($row = mysqli_fetch_assoc($res)) {
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Registration number</th>
<th>Company Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><button type="submit" class="btn btn-default myButton" value="$row['/companyid/']" id="accept" name="accept">Remove</button></td>
<td>$row['/companyid/']</td>
<td>$row['/government_reg_no/']</td>
<td>$row['/company_name/']</td>
<td>$row['/email/']</td>
</tr>
</tbody>
</table>
<?php
}
';
}
?>[![enter image description here][1]][1]
線27
<td align="center"><button type="submit" class="btn btn-default myButton" value="$row['/companyid/']" id="accept" name="accept">Remove</button></td>
你的問題是什麼?請清楚解釋你的問題,包括你的*預期*比。 *當前*輸出等。 –
是否有代碼缺失或錯字? 'echo'while($ row = mysqli_fetch_assoc($ res)){' - >你是否嘗試回顯循環? – OldPadawan
請使用'error_reporting(E_ALL); ini_set('display_errors',1);'在你的頁面頂部,讓我們知道PHP告訴你什麼,如果錯誤... – OldPadawan