东城︶ㄣLee 发表于 2012-3-28 22:52:35

分页sql语句带参数,如何解决参数传递问题?

本帖最后由 东城︶ㄣLee 于 2012-3-28 22:55 编辑

$sql语句中的$data['search_type']和$data['spell']是从表单中提交得来的。点击分页链接时,程序会回到这段,而这个过程是没有表单提交过程的,此时的$data['search_type']和$data['spell']都未定义,致使程序运行不通过。看了论坛上一些分页的帖子,都是不传参数的,求高人提供解决方法。


$sql = "SELECT words.spell,words.class_abbr,words.meaning_cn FROM words WHERE id in (SELECT word_affix.word_id FROM word_affix WHERE word_affix.affix_id = (SELECT affixes.id FROM affixes WHERE (affixes.class=".$data['search_type']." AND affixes.name = '".$data['spell']."'))) ";
                     
$data['word_affix'] = $this->words_model->get_words_by_affix($sql);

if (empty($data['word_affix']))
{
      $data['page_title'] = 'Affix Not Found!';
      $this->load->view('templates/header', $data);
      $this->load->view('words/query', $data);
}else{

      $limit = 10;
      //每页显示数目
      $config['base_url'] = base_url().'/index.php/words/query_pagina';
      //base_url可以防止换域名代码错误。
      //获得总数。
      $config['total_rows'] = count($data['word_affix']);
      $config['per_page'] = $limit;
      $config['first_link'] = 'Start';
      $config['last_link'] = 'End';
      $config['num_links'] = 10;
      //$config['uri_segment'] = 3; //url segment max number
      //上面是自定义文字以及左右的连接数
      $this->pagination->initialize($config);
      //初始化配置
      $data['limit']=$limit;
      $data['offset']=$offset;
      $data['pagination']=$this->pagination->create_links();
      //通过数组传递参数
      $data['word_affix_array'] = $this->words_model->get_words_by_affix_pagina($sql, $limit, $offset);
      $data['page_title'] = 'EM World';
      $this->load->view('templates/header', $data);
      $this->load->view('words/querypagina', $data);

}













东城︶ㄣLee 发表于 2012-3-28 23:16:06

晕,解决了,直接参数传递就可以了


if($search_type!=''){
        $data['search_type'] = $search_type;
}
if($spell!=''){
        $data['spell'] = $spell;
}

$config['base_url'] = base_url().'/index.php/words/query_pagina/'.$data['search_type'].'/'.$data['spell'].'/';

xuqin 发表于 2012-5-22 14:13:34

呵呵我也迷惑
看了后,晕直接传参数就可以了

谢谢楼主:lol

Anonymous 发表于 2014-4-22 20:44:19

匀碑皆抨曾扳齐/////////////////现在好像都在用这个,效果还不错,分享给大家!

lisheng51 发表于 2014-4-22 23:27:21

我没用ci自带的分页,都是用js完成的
页: [1]
查看完整版本: 分页sql语句带参数,如何解决参数传递问题?