【发布时间】:2015-12-24 06:54:38
【问题描述】:
这是我的标题中用于搜索选项的 html 代码
<div class="nav search-row" id="top_menu">
<!-- search form start -->
<ul class="nav top-menu">
<li>
<form class="navbar-form">
<a href="search.php">
<input class="form-control" placeholder="Search" type="text">
</a>
</form>
</li>
</ul>
<!-- search form end -->
</div>
这是我的 search.php 页面。功能/代码在哪里。我不确定我哪里出错了,或者这就是搜索代码的工作方式。我正在根据搜索输入中输入的内容从数据库中检索数据
<?php
include("head.php");
global $conn;
$search = $_POST['search'];
if ($stmt = $conn->prepare("SELECT gig_id, user_id, category_id, description, price, img, deliverytime, created_at, updated_at, language from advertisement WHERE description = 'search' "))
{
$result = $stmt->execute();
$stmt->bind_result($gig_id, $user_id, $category_id, $description, $price, $img, $deliverytime, $created_at, $updated_at, $language);
while ($stmt->fetch())
{
$rows[] = array('gig_id' => $gig_id, 'user_id' => $user_id, 'category_id' => $category_id, 'description' => $description, 'price' => $price, 'img' => $img, 'deliverytime' => $deliverytime, 'created_at' => $created_at, 'updated_at' => $updated_at, 'language' => $language);
}
$stmt->close();
}
else
echo "error";
?>
我在这里获取我输入的内容并在容器中显示信息
<?php
if(isset($_POST['search']))
{
$search = $_POST['search'];
<?php foreach ($rows as $row): ?>
<div class="col-sm-4 col-md-4 col-lg-4 col-xs-6">
<div class="thumbnail"> <img src="<?php echo 'GigUploads/'.$row['img']; ?>" alt="<?php echo $row['description']; ?>" height="200" width="400">
<div class="caption">
<h3><?php echo $row['description']; ?></h3>
<!-- Passing the gig_id through the URL. Get the gig_id from the URL in the detail page using $_GET['gig_id'] -->
<p><a href="detail.php?gig_id=<?php echo $row['gig_id']; ?>" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Request</a></p>
</div>
</div>
</div>
?>
<?php endforeach; ?>
}
【问题讨论】:
-
WHERE description LIKE '%search%'