0

--

-- 数据库:ci-intro

创建数据库ci-intro默认字符集 utf8 COLLATE utf8_general_ci; 使用ci-intro


--

-- 表的表结构posts

如果不存在则创建表posts( idint(11) unsigned NOT NULL AUTO_INCREMENT, titlevarchar(100) DEFAULT NULL, bodytext, createddatetime DEFAULT NULL, modifieddatetime DEFAULT NULL, PRIMARY KEY ( id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6;

--

-- 为表转储数据posts

INSERT INTO posts( id, title, body, created, modified) VALUES (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, 'Thank GOD', '一切都属于我父亲', '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, '无聊posts', '事件日记不感兴趣', '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); 
}
4

1 回答 1

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();

您可以在此处浏览文档...以阅读有关分页类的更多信息...以及有关自定义的信息

于 2013-04-05T04:59:39.590 回答