我是编程世界的新手,我正在开发一款具有搜索功能的应用。 我的问题是以下代码无法从数据库输出搜索数据。 我正在使用require_once命令通过header.php为此输出插入我的数据库连接。
请帮忙。
<!DOCTYPE html>
<html lang="">
<?php require_once('Include/Top.php');?>
<body>
<?php require_once('Include/header.php'); ?>
<centre>
<div class="searchboxsearch">
<div class="row">
<div class="col-xs-12">
<br><br><br><br>
<form action="" method="get">
<div class="form-group">
<input type="text" id="usermame" class="form-control" name="username" placeholder="Search a Name">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="Search">
</form>
</div>
</div>
</div>
<?php
$sname = $_GET['username'];
$terms = explode(" ", $sname);
foreach ($terms as $each)
{
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%'";
else
$query .= "keywords LIKE '%$each%'";
}
$query = "SELECT * FROM feedback WHERE $query";
$srun = mysqli_query($connection, $query);
if (mysqli_num_rows($srun) > 0)
{
while($row = mysqli_fetch_assoc($srun))
{
$name =ucfirst($row['fullname']);
$date =$row['date'];
$feedback = $row['feedback'];
echo "<h3> $name</a></h3>
$feedback <br /> $stdate";
}
}else
{
echo " No result found";
}
?>
</centre>
<?php require_once('Include/footer.php'); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>
三江源
KP