#416 添加了计划搜索功能

This commit is contained in:
Li Jianxuan 2012-11-15 09:45:47 +00:00
parent 0b26aa6aff
commit 211e2ecf04
2 changed files with 42 additions and 2 deletions

View File

@ -755,7 +755,39 @@ class HeiheController extends DataController
{ {
$this->_helper->viewRenderer('project-index'); $this->_helper->viewRenderer('project-index');
$sql = "SELECT * FROM heiheproject //Search Link
$this->view->searchLink = "/heihe/projects/ac/index/";
$q = $this->_getParam('q');
$wheresql = array();
if(!empty($q))
{
if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$q))
{
$this->view->error = "输入的搜索条件有误,只允许输入汉字、数字、字母";
return true;
}
$wheresql[] = " (title LIKE '%$q%' OR
code LIKE '%$q%' OR
name LIKE '%$q%')";
$this->view->searchKeyword = $q;
}
if(count($wheresql)>0)
{
$wheresql = join(" AND ",$wheresql);
}else{
$wheresql = "";
}
if(!empty($wheresql))
{
$wheresql = " WHERE ".$wheresql;
}
$sql = "SELECT * FROM heiheproject $wheresql
ORDER BY id DESC"; ORDER BY id DESC";
$sth = $this->db->query($sql); $sth = $this->db->query($sql);
$rows = $sth->fetchAll(); $rows = $sth->fetchAll();

View File

@ -31,6 +31,14 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');
<li class="box-shadow"><a class="text-shadow" href="/heihe/projects/ac/submit">已提交</a></li> <li class="box-shadow"><a class="text-shadow" href="/heihe/projects/ac/submit">已提交</a></li>
</ul> </ul>
</div> </div>
<?php if(!empty($this->searchLink)){ ?>
<div>
<form id="datasearch" class="search_form" action="<?= $this->searchLink ?>">
<input type="text" id="keyword" name="q" value="<?= $this->searchKeyword; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button>
</form>
</div>
<?php }?>
<div id="datalist"> <div id="datalist">
<?php <?php
if (count($this->paginator)): if (count($this->paginator)):