我尝试了一些搜索数据库表条目的代码。代码运行良好。我想在同一页面上显示div的结果。我无法获得这个的Ajax代码。我已经尝试了很多次。
形式
<head>
<script type="text/javascript" src="engine1/jquery.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript">
$(document).ready(function(){
//can't get the ajax code
});
</script>
</head>
<div class="login">
<form action="result.php" id="search_form" method="POST">
<p><input name="query" autocomplete="off" id="list_search" type="search" required class="search" /></p>
<p align="center">
<input type="submit" id="click" name="click" class="but" value=" search" />
</p>
</form>
</div>
<div class="coupons">
</div>
result.php
if($_POST['click']) {
$keyword = mysqli_real_escape_string($con,$_POST['query']); // always escape
$keys = explode(" ", $keyword);
$sql="SELECT c.* , sc.* , sm.* ,ca.* from store_category sc INNER JOIN store_manufacture sm ON sm.sm_id=sc.store_id INNER JOIN categories ca ON ca.cat_id=sc.cat_id INNER JOIN coupons c on c.c_sc_id=sc.sc_id WHERE c.c_name LIKE '%$keyword%' OR sm.sm_brand_name LIKE '%$keyword%' OR ca.cat_name LIKE '%$keyword%' OR c.c_description LIKE '%$keyword%' LIMIT 10";
foreach ($keys as $k) {
$sql.="OR c.c_name LIKE '%$k%' OR sm.sm_brand_name LIKE '%$k%' OR ca.cat_name LIKE '%$k%' OR c.c_description LIKE '%$k%'";
}
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo $row['c_name'];
echo $row ['c_description'];
echo $row['sm_brand_name'];
}
}