广告增加按类别搜索

webht/payment
Jimmy Liow 2 years ago
parent 622ca4878e
commit 1a40cb100d

@ -31,9 +31,10 @@ class Index extends CI_Controller
{
$keywords = $this->input->post('keywords');
$byWhat = $this->input->post('byWhat');
$data = array();
$data['groupList'] = $this->Information_model->group_list();
$data['tipsList'] = $this->infoTips_model->search($keywords);
$data['tipsList'] = $this->infoTips_model->search($keywords, $byWhat);
$this->load->view('bootstrap3/header', $data);
$this->load->view('welcome');
$this->load->view('bootstrap3/footer');

@ -57,17 +57,13 @@ class infoTips_model extends CI_Model
}
// keyword 可以是标题或者 URL使用空格分开
public function search($keywords) {
$keywordList = explode(" ", $keywords);
$whereCodition = ' and (';
foreach ($keywordList as $index => $keyword) {
if ($index > 0) {
$whereCodition .= " or ";
}
$whereCodition .= "it.it_title like '%" . $keyword . "%'";
}
foreach ($keywordList as $index => $keyword) {
$whereCodition .= " or it.it_content like '%" . $keyword . "%'";
public function search($keywords, $byWhat) {
if ($byWhat == 'byTitle') {
$whereCodition .= " and it.it_title like '%" . $keyword . "%'";
} else if ($byWhat == 'byLabel') {
$whereCodition .= " and it.it_code like '%" . $keyword . "%'";
} else if ($byWhat == 'byContent') {
$whereCodition .= " and it.it_content like '%" . $keyword . "%'";
}
$searchText =
"select it.it_id ,it.it_title,it.it_expires,it.it_code,it.it_content,it.it_sitecode,it.it_datetime

@ -5,14 +5,39 @@
</div>
<div class="col-md-9">
<h4>广告管理 <small><a href="<?php echo site_url('thirdparty/recommend/tips/add'); ?>">添加广告</a></small></h4>
<form method="post" action="<?php echo site_url('thirdparty/recommend/index/search'); ?>" class="navbar-form navbar-left">
<form id="searchForm" method="post" action="<?php echo site_url('thirdparty/recommend/index/search'); ?>" class="navbar-form navbar-left">
<div class="input-group">
<input type="text" class="form-control input-sm" name="keywords" id="keywords" value="" style="min-width:450px;">
<input type="hidden" name="byWhat" id="byWhatInput" >
<span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit">搜索</button>
<button class="btn btn-default btn-sm" id="searchByTitleBtn" type="button">搜索标题</button>
<button class="btn btn-default btn-sm" id="searchByLabelBtn" type="button">搜索标签</button>
<button class="btn btn-default btn-sm" id="searchByContentBtn" type="button">搜索内容</button>
</span>
</div>
</form>
<script>
var searchForm = document.getElementById('searchForm');
var searchByTitleBtn = document.getElementById('searchByTitleBtn');
var searchByLabelBtn = document.getElementById('searchByLabelBtn');
var searchByContentBtn = document.getElementById('searchByContentBtn');
var byWhatInput = document.getElementById('byWhatInput');
function submitSearch(byWhat) {
byWhatInput.value = byWhat;
searchForm.submit();
}
searchByTitleBtn.addEventListener('click', function(event) {
submitSearch('byTitle');
});
searchByLabelBtn.addEventListener('click', function(event) {
submitSearch('byLabel');
});
searchByContentBtn.addEventListener('click', function(event) {
submitSearch('byContent');
});
</script>
<table class="table table-striped">
<thead>

Loading…
Cancel
Save