|
本帖最后由 knight、 于 2016-8-3 16:09 编辑
HTML复制代码 </head><body>
<div>
<table [/color][color=#bababa]width=[/color][color=#a5c261]"500px"[/color][color=#e8bf6a]>
<tr>
<th>ID号 </th>
<th>编写者姓名 </th>
<th>新闻标题 </th>
<th>新闻内容 </th>
<th>上传时间 </th>
</tr>
<?php foreach [/b][/backcolor][/color][backcolor=#232525]([/backcolor][color=#9876aa][backcolor=#232525]$selectList [/backcolor][/color][color=#cc7832][backcolor=#232525][b]as [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525]): [/backcolor][color=#cc7832][backcolor=#232525][b]?><tr [/color][color=#bababa]style=[/color][color=#a5c261]"text-align: center;"[/color][color=#e8bf6a]>
<td><?php echo [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525][[/backcolor][color=#6a8759][backcolor=#232525]'id'[/backcolor][/color][backcolor=#232525]] [/backcolor][color=#cc7832][backcolor=#232525][b]?></td>
<td><?php echo [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525][[/backcolor][color=#6a8759][backcolor=#232525]'name'[/backcolor][/color][backcolor=#232525]] [/backcolor][color=#cc7832][backcolor=#232525];[/backcolor][/color][color=#cc7832][backcolor=#232525][b]?></td>
<td><?php echo [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525][[/backcolor][color=#6a8759][backcolor=#232525]'title'[/backcolor][/color][backcolor=#232525]] [/backcolor][color=#cc7832][backcolor=#232525];[/backcolor][/color][color=#cc7832][backcolor=#232525][b]?></td>
<td><?php echo [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525][[/backcolor][color=#6a8759][backcolor=#232525]'news'[/backcolor][/color][backcolor=#232525]] [/backcolor][color=#cc7832][backcolor=#232525];[/backcolor][/color][color=#cc7832][backcolor=#232525][b]?></td>
<td><?php echo [/b][/backcolor][/color][color=#9876aa][backcolor=#232525]$item[/backcolor][/color][backcolor=#232525][[/backcolor][color=#6a8759][backcolor=#232525]'savetime'[/backcolor][/color][backcolor=#232525]] [/backcolor][color=#cc7832][backcolor=#232525];[/backcolor][/color][color=#cc7832][backcolor=#232525][b]?></td>
<td><a [/color][color=#bababa]href = [/color][color=#a5c261]"\show_news/del/<?php echo $item['id'] ?>">删除 </a></td>
<td><a [/color][color=#bababa]href = [/color][color=#a5c261]"\show_news/modify/<?php echo $item['id'] ?>">修改 </a></td>
</tr>
<?php endforeach[/b][/backcolor][/color][color=#cc7832][backcolor=#232525]; [/backcolor][/color][color=#cc7832][backcolor=#232525][b]?></table>
<form [/color][color=#bababa]action=[/color][color=#a5c261]"/show_news/select" [/color][color=#bababa]method=[/color][color=#a5c261]"get" [/color][color=#bababa]name=[/color][color=#a5c261]"s" [/color][color=#bababa]accept-charset=[/color][color=#a5c261]"utf-8" [/color][color=#e8bf6a]/>
按编写者查询 <input [/color][color=#bababa]type = [/color][color=#a5c261]"text" [/color][color=#bababa]name = [/color][color=#a5c261]"xm"[/color][color=#e8bf6a]>
按标题查询 <input [/color][color=#bababa]type = [/color][color=#a5c261]"text" [/color][color=#bababa]name = [/color][color=#a5c261]"bt"[/color][color=#e8bf6a]>
按新闻查询 <input [/color][color=#bababa]type = [/color][color=#a5c261]"text" [/color][color=#bababa]name = [/color][color=#a5c261]"xw"[/color][color=#e8bf6a]>
按时间查询 <input [/color][color=#bababa]type = [/color][color=#a5c261]"text" [/color][color=#bababa]name = [/color][color=#a5c261]"sj"[/color][color=#e8bf6a]>
<input [/color][color=#bababa]type=[/color][color=#a5c261]"submit" [/color][color=#bababa]name=[/color][color=#a5c261]"submit" [/color][color=#bababa]value=[/color][color=#a5c261]"查询" [/color][color=#e8bf6a]/>
</form>
<a [/color][color=#bababa]href = [/color][color=#a5c261]"/show_news/index"[/color][color=#e8bf6a]>回到首页 </a></br>
</div>
</body>
</html> 复制代码 上面是视图,提交查询条件的PHP复制代码 [color=rgb(204, 120, 50)][backcolor=rgb(35, 37, 37)][size=10.5pt][b]function [/b][/size][/backcolor][/color][color=rgb(255, 198, 109)][backcolor=rgb(35, 37, 37)][size=10.5pt]select[/size][/backcolor][/color][backcolor=rgb(35, 37, 37)][size=10.5pt]() {[/size][/backcolor][backcolor=#232525] $query = $this->show_news_model->select();
[/backcolor][/color][color=#cc7832] //将结果集作为关联数组返回
[/backcolor][/color][color=#808080] $data['selectList'] = $query;
[/backcolor][/color][color=#cc7832] $this->load->view('select',$data); 复制代码
}上面是控制器方法,来调用下面的模型PHP复制代码 [backcolor=rgb(35, 37, 37)][size=10.5pt] [/size][/backcolor][color=rgb(204, 120, 50)][backcolor=rgb(35, 37, 37)][size=10.5pt][b]function [/b][/size][/backcolor][/color][color=rgb(255, 198, 109)][backcolor=rgb(35, 37, 37)][size=10.5pt]select[/size][/backcolor][/color][backcolor=rgb(35, 37, 37)][size=10.5pt]()[/size][/backcolor][backcolor=#232525] {
[/backcolor][backcolor=#232525] $this->load->database();
[/backcolor][/color][color=#cc7832] parse_str($_SERVER['QUERY_STRING'], $_GET);
[/backcolor][/color][color=#cc7832] $data['xm'] = $this->input->get('xm');
[/backcolor][/color][color=#cc7832] $data['bt'] = $this->input->get('bt');
[/backcolor][/color][color=#cc7832] $data['xw'] = $this->input->get('xw');
[/backcolor][/color][color=#cc7832] $data['sj'] = $this->input->get('sj');
[/backcolor][/color][color=#808080]// $data['xm'] = "knight";
[/backcolor][/color][color=#808080]// $data['bt'] = $this->input->get('bt');
[/backcolor][/color][color=#808080]// $data['xw'] = $this->input->get('xw');
[/backcolor][/color][color=#808080]// $data['sj'] = $this->input->get('sj');
[/backcolor][/color][color=#808080] echo 'data';
[/backcolor][/color][color=#cc7832] var_dump($data);
[/backcolor][/color][color=#cc7832] $info = array();
[/backcolor][/color][color=#cc7832] if($data['xm'] != '') {
[/backcolor][backcolor=#232525] $info['name'] = $data['xm'];
[/backcolor][/color][color=#cc7832] }
[/backcolor][backcolor=#232525] if($data['bt'] != '') {
[/backcolor][backcolor=#232525] $info['title'] = $data['bt'];
[/backcolor][/color][color=#cc7832] }
[/backcolor][backcolor=#232525] if($data['xw'] != '') {
[/backcolor][backcolor=#232525] $info['news'] = $data['xw'];
[/backcolor][/color][color=#cc7832] }
[/backcolor][backcolor=#232525] if($data['sj'] != '') {
[/backcolor][backcolor=#232525] $info['savetime'] = $data['sj'];
[/backcolor][/color][color=#cc7832] }
[/backcolor][color=#808080]// $info = array('name' => $data['xm'],'title' => $data['bt'],'news' => $data['xw'],'savetime' => $data['sj']);
[/backcolor][/color][color=#808080] $this->db->where($info);
[/backcolor][/color][color=#cc7832] $this->db->select("*");
[/backcolor][/color][color=#cc7832] $result = $this->db->get('news')->result_array();
[/backcolor][/color][color=#cc7832] echo $this->db->last_query();
[/backcolor][/color][color=#cc7832] return $result;
[/backcolor][/color][color=#cc7832] }
[backcolor=rgb(35, 37, 37)][backcolor=rgb(255, 255, 255)] 复制代码 现在的问题就是对这个查询的结果进行分页应该怎么写呢。求大神指点
|
|