-
ci-intro
创建数据库ci-intro
默认字符集utf8 COLLATE utf8_general_ci;
使用ci-intro
;
-
posts
CREATE TABLE IF NOT NOT EXISTS posts
(
id
int(11)unsigned NOT NULL AUTO_INCREMENT,
title
varchar(100)DEFAULT NULL,
body
文字,
created
datetime DEFAULT NULL,
modified
datetime DEFAULT NULL,
主要关键(id
)
)ENGINE = InnoDB DEFAULT CHARSET = utf8 AUTO_INCREMENT = 6;
-
posts
INSERT INTO posts
(id
,title
,body
,created
,modified
)价值观
(1,'另一天仍然看','我的狮子跑了','2013-04-02 08:20:20','2013-04-03 12:43:49',
(2,'美好的一天','狮子回归一片。','2013-04-02 08:20:44','2013-04-02 08:20:44'),
(3,'感谢上帝','一切都属于我父亲','2013-04-02 08:21:03','2013-04-02 08:21:03'),
(4,'在海边','我们下到海边,然后开始下雨!','2013-04-02 08:21:35','2013-04-03 19:28:48' )
(5,'无聊的帖子','事件日记不是很有趣','2013-04-02 08:21:55','2013-04-03 19:35:25';
应用\控制器\ posts.php
function search()
{
$data['title'] = "Blogging";
$data['heading'] = "Bloging";
$this->load->view('view_search', $data);
}
应用\视图\ view_search.php
<?php echo form_fieldset('<b>Search a Post!</b>');?>
<?php echo form_open('posts/execute_search'); ?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" style="border:dashed" bgcolor="#FFCC99">
<tr>
<td align="right">
<?php echo form_label('Search: enter keyword, title, content '); ?>
</td>
<td>
<?php echo form_input(array('name'=>'search')); ?>
</td>
</tr>
<tr>
<td align="right" valign="top"><?php echo nbs(1); ?></td>
<td valign="top" class="style1"><?php echo form_submit('search_submit','Submit'); ?></td>
</tr>
</table>
<?php echo form_close(); ?>
<?php echo form_fieldset_close(); ?>
应用\控制器\ posts.php
public function execute_search($search_term)
{
$data['title'] = "Blogging";
$data['heading'] = "Bloging";
$search_term = $_POST['search'];
$rs = $this->db->like('title', trim($search_term))
->or_like('body', trim($search_term))
->get('posts');
$total = $rs->num_rows();
$data['results'] = $rs->result();
$this->load->view("view_index", $data);
}
答案 0 :(得分:2)
使用分页..你需要使用codeigniter的分页类库...加载库
$this->load->library('pagination');
并在控制器中调用函数
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
并打印create_lnks,希望您的分页保留...(查看)..
echo $this->pagination->create_links();
您可以查看文档here ...以了解有关分页类的更多信息以及有关自定义的信息