我有一个看起来像这样的高级表格:
我正在使用来自 Bootsnipp 的模板,其中包含我的代码,并且正在尝试对其进行调整 - 可在此处获得。
我进行搜索的方法是根据搜索将值附加到特定的 URL 参数,然后在 PHP 代码中进一步检查这些参数是否为空白或包含值,然后执行从数据库中获取拍卖的代码。
自从我开始这样做以来,“按状态过滤”按钮没有填充数据库中的状态过滤器(唯一出现的是空白选项),而且我的搜索按钮(带有眼镜图标)也有消失了。不知道为什么,因为这以前有效。注意我正在使用 PDO。这是过滤器部分的 HTML 和 PHP 代码:
<!-- Page Content -->
<div class="container">
<!--This is the search bar-->
<div class="container">
<div class="row">
<div class="col-sm-12">
<!-- http://stackoverflow.com/questions/8476602/appending-get-parameters-to-url-from-form-action-->
<!--If this is a form it messes up the styling-->
<div method="get" class="input-group" id="adv-search" action="listings.php">
<input type="text" name="q" class="form-control"
placeholder="Search for auctions by name or description" value=""/>
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filter">Sort By</label>
<select class="form-control" name="sort" value="by_lowest_time">
<!-- By default by lowest time remaining-->
<option value="by_lowest_time" selected>Lowest Time Remaining</option>
<option value="by_highest_time">Highest Time Remaining</option>
<option value="by_lowest_price">Lowest Price</option>
<option value="by_highest_price">Highest Price</option>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by Category</label>
<?php
try {
$catsql = 'SELECT * FROM ebay_clone.Category';
$catq = $db->query($catsql);
$catq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="cat">
<option value=""></option>
<!-- http://stackoverflow.com/questions/3078192/how-to-set-html-value-attribute-with-spaces-using-php-->
<?php while ($r = $catq->fetch()): ?>
<option
value="<?php echo str_replace(' ', '_', strtolower(htmlspecialchars($r['item_category']))); ?>"> <?php echo htmlspecialchars($r['item_category']) ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by State</label>
<?php
try {
// error_reporting(E_ERROR | E_PARSE);
$statsql = 'SELECT * FROM ebay_clone.State';
$statq = $db->query($statsql);
$statq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="state">
<!-- Blank option-->
<option value=""></option>
<?php while ($r = $statq->fetch()): ?>
<option value="<?php echo trimstr_replace(' ', '_', strtolower(htmlspecialchars($r['state']))); ?>"> <?php echo htmlspecialchars($r['state']) ?> </option>
<?php endwhile; ?>
</select>
</div>
<button type="button" value="search" class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
</div>
</div>
</div>
</div>