我正在尝试对我的homepage_content视图进行搜索和过滤,但我在搜索输入中获得搜索结果,并在其下方过滤(不知道如何过滤需要帮助)查看请查看我的代码。
我的控制器:
Templates.php
function _filter_action()
{
$this->load->module('store_items');
$search = $this->input->post('search');
$submit = $this->input->post('submit');
if(isset($submit)) {
if($this->input->post('search') == '')
{
redirect(base_url());
}
$str = $this->db->escape_str($search);
$query = "SELECT * FROM store_items WHERE item_title LIKE '%$str%'" ;
$mysql_query = $this->store_items->_custom_query($query);
foreach ($mysql_query->result() as $row) {
echo "<a href='index.php/mobile/phone/$row->item_url'><img src='small_pics/$row->small_pic' class='img-responsive' title='$row->item_title'>(\"".$row->item_title."\");'>" . $row->item_title . "<br><br>'</a>";
}
}
}
function _filter()
{
$this->load->view('filter');
}
function _search_action()
{
$submit = $this->input->post('submit');
if(isset($submit)) {
$this->load->view('search_result');
}
}
function _search_bar()
{
$this->load->view('search_bar');
}
Store_items.php
function _custom_query($mysql_query)
{
$this->load->model('mdl_store_items');
$query = $this->mdl_store_items->_custom_query($mysql_query);
return $query;
}
我的观点:
Search_bar.php
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?= base_url() ?>" style="font-weight: bold; color:black">ShopBuzz</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<th>
<form method="post" class="navbar-form navbar-left col-md-11" action="<?= Modules::run('templates/_search_action')?>">
<div class="form-group">
<input type="text" name="search" class="form-control" placeholder="Search">
</div>
<button type="submit" name="submit" value="Submit" class="btn btn-primary">Submit</button>
</form>
</th>
</div>
</div>
</nav>
<br><br>
Search_result.php
<?php
$this->load->module('store_items');
$search = $this->input->post('search');
$submit = $this->input->post('submit');
$base_url = base_url('index.php');
$this->load->module('site_settings');
$currency_symbol = $this->site_settings->_get_currency_symbol();
$str = $this->db->escape_str($search);
$query = "SELECT * FROM store_items WHERE item_title LIKE '%$str%'";
if($this->input->post('search') == '')
{
redirect(base_url());
}
$mysql_query = $this->store_items->_custom_query($query);
foreach ($mysql_query->result() as $row) {?>
<div class="container-fluid">
<div class="row">
<div class="col-md-5" style="background-color:white; min-height: 300px;">
<div>
<br>
</div>
<a href='<?=$base_url?>/mobile/phone/<?=$row->item_url?>'><img src='small_pics/<?=$row->small_pic?>' class='img-responsive' title='<?=$row->item_title?>'><?=$row->item_title?></a><br><?= nl2br('---------------------------------------------------') ?>
</div>
<?= nbs(120);?>
<div class="col-md-7" style="background-color:orange; min-height: 300px;">
<div>
<br>
</div>
<?php
if ($row->was_price == 0) {
$discount = '';
$discountper = '';
}
else{
$discount = $row->was_price - $row->item_price;
$discountper = intval($discount/$row->was_price*100)."% off";
}
?>
<?= "<h2>Price: ".$currency_symbol.number_format($row->item_price)."</h2><h3>".$discountper."</h3><h3>Highlights:</h3><br>Ram: ".$row->item_ram. "<br>Rom: " .$row->item_rom. "<br>Camera: " .$row->item_camera. "<br>Display: " .$row->item_display. "<br>Battery: " .$row->item_battery. "<br>Processor: " .$row->item_processor?><br><br><br><?= nl2br('-----------------------------------------------------------------------------------------------------------------------') ?>
</div>
</div>
</div>
<?php
}
?>
filter.php
<?php
$this->load->module('store_items');
$search = $this->input->post('search');
$str = $this->db->escape_str($search);
$fetch_item_ram = "SELECT GROUP_CONCAT(DISTINCT item_ram) AS ram FROM store_items WHERE item_title LIKE '%$str%' GROUP BY item_ram";
$mysql_query_ram = $this->store_items->_custom_query($fetch_item_ram);
$fetch_item_rom = "SELECT GROUP_CONCAT(DISTINCT item_rom) AS rom FROM store_items WHERE item_title LIKE '%$str%' GROUP BY item_rom";
$mysql_query_rom = $this->store_items->_custom_query($fetch_item_rom);
$fetch_item_price = "SELECT '20000 - 30000' AS price, COUNT(*) FROM store_items
WHERE item_price >= 20000 AND item_price <= 30000
UNION
SELECT '30000 - 40000', COUNT(*) FROM store_items
WHERE item_price >= 30000 AND item_price <= 40000";
$mysql_query_price = $this->store_items->_custom_query($fetch_item_price);
$fetch_item_display = "SELECT GROUP_CONCAT(DISTINCT item_display) AS display FROM store_items WHERE item_title LIKE '%$str%' GROUP BY item_display";
$mysql_query_display = $this->store_items->_custom_query($fetch_item_display);
?>
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-6 col-md-offset-3 col-lg-offset-0">
<div class="well">
<h3 align="center">Search Filter</h3>
<form class="form-horizontal">
<div class="form-group">
<label for="type1" class="control-label">Price</label>
<select class="form-control" name="" id="type1">
<option value="priceselected" selected="" disabled="">Please Select Price</option>
<?php foreach ($mysql_query_price->result() as $row) {?>
<option value="price"><?php echo $row->price; ?></option><?php } ?>
</select>
</div>
<div class="form-group">
<label for="type1" class="control-label">Ram</label>
<select class="form-control" name="" id="type1">
<option value="ramselected" selected="" disabled="">Please Select Ram</option>
<?php foreach ($mysql_query_ram->result() as $row) {?>
<option value="ram"><?php echo $row->ram; ?></option><?php } ?>
</select>
</div>
<div class="form-group">
<label for="type1" class="control-label">Rom</label>
<select class="form-control" name="" id="type1">
<option value="romselected" selected="" disabled="">Please Select Rom</option>
<?php foreach ($mysql_query_rom->result() as $row) {?>
<option value="rom"><?php echo $row->rom; ?></option><?php } ?>
</select>
</div>
<div class="form-group">
<label for="type1" class="control-label">Screen Size</label>
<select class="form-control" name="" id="type1">
<option value="displayselected" selected="" disabled="">Please Select Display</option>
<?php foreach ($mysql_query_display->result() as $row) {?>
<option value="display"><?php echo $row->display; ?></option><?php } ?>
</select>
</div>
<p class="text-center"><a href="#" class="btn btn-danger glyphicon glyphicon-search" role="button"></a></p>
</form>
</div>
</div>
</div>
</div>
Homepage_content.php
<br>
<br>
<div id="navbar" class="navbar-collapse collapse">
<?php
echo Modules::run('templates/_search_bar');
?>
<?php
$submit = $this->input->post('submit');
if (isset($submit)) {
if($this->input->post('search') == '')
{
echo "<br><strong>No Data Found</strong>";
}
echo Modules::run('templates/_filter');
}
?>
</div><!--/.navbar-collapse -->
<?php
echo Modules::run('homepage_blocks/_draw_blocks');
?>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-4">
<h2>Heading</h2>
<a href="#">CLICK HERE</a><p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
<div class="col-md-4">
<h2>Heading</h2>
<a href="#">CLICK HERE</a><p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>