今天到公布欄最後一個功能了
controllers/news.php
新增一個方法
function LikeNews(){
$like = $this->input->post('title');
$data['query'] = $this->sql->like('title',$like,'news');
$this->load->view('news',$data);
}
models/sql.php
/*
* $this->db->like('欄位','查詢訊息','模式');
* 模式有分 'before'、'after' 以及 'both' (這是預設值)
*/
function like($title,$like,$table){
$query = $this->db->like($title,$like)->get($table);
return $query;
}
views/news.php
最終版
<?php
/*---------------------------------------*/
//........ 此頁面請放在view資料夾底下.......//
/*---------------------------------------*/
$link = 'http://localhost/test/';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>公佈欄</title>
<!--以下是 Bootstrap 的文件包-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="<?=$link;?>css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="<?=$link;?>css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="<?=$link;?>js/jquery.js"></script>
<script src="<?=$link;?>js/bootstrap.min.js"></script>
<style>
#heig{
height:10px;
}
#color{
background-color: #E5E5E5;
}
</style>
<!--"container"為固定置中,請參考 http://kkbruce.tw/Bootstrap/Scaffolding 佈局篇-->
<div class="container">
<!--class="table table-bordered table-condensed"請參考 http://kkbruce.tw/Bootstrap/BaseCSS#tables -->
<table width="1200" border="0" class="table table-bordered table-condensed">
<tr>
<td colspan="2" bgcolor="#CCCCCC"><div align="center"><strong>公佈欄</strong></div></td>
</tr>
<tr>
<td>
<!-- 請參考 http://kkbruce.tw/Bootstrap/BaseCSS#forms -->
<div id="heig">
<form action="<?=$link;?>index1.php/news/LikeNews"" method="post" name="like" class="form-inline" id="like">
<strong>搜尋標題: </strong>
<label>
<input type="text" name="title"/>
</label>
<button class="btn" type="submit">搜尋</button>
</form>
</div>
</td>
<td>
<div align="center">
<!-- 請參考 http://kkbruce.tw/Bootstrap/BaseCSS#buttons -->
<a href="<?=$link;?>index1.php/news/AddNews"><button class="btn" type="button">新增公告</button></a>
</div></td>
</tr>
<tr>
<td colspan="2"><table width="1200" border="0" class="table table-bordered table-condensed table-striped table-hover">
<tr>
<td id="color"><div align="center"><strong>項次</strong></div></td>
<td id="color"><div align="center"><strong>標題</strong></div></td>
<td id="color"><div align="center"><strong>時間</strong></div></td>
<td id="color"><div align="center"><strong>管理</strong></div></td>
</tr>
<?php
/** result_array() 參考 http://www.codeigniter.org.tw/user_guide/database/results.html **/
foreach($query->result_array() as $key=>$row):
?>
<tr>
<td><div align="center"><?=$key+1;?></div></td>
<td><div align="center"><?=$row['title'];?></div></td>
<td><div align="center"><?=$row['date'];?></div></td>
<td><div align="center">
<a href="<?=$link;?>index1.php/news/ModifyNews/<?=$row['id'];?>"><button class="btn" type="button">修改</button></a>
<a href="<?=$link;?>index1.php/news/DelNews/<?=$row['id'];?>"><button class="btn" type="button" onclick="if(confirm('您確定刪除<?=$row['title'];?>嗎?')) return true;else return false">刪除</button></a>
</div></td>
</tr>
<?php endforeach; ?>
</table></td>
</tr>
</table>
</div>
使用圖
待續..