0

让我详细解释我的问题

我有一张名为 products 的表

Products : Name , views , sale_wanted , added_date

我在视图中列出了我的所有产品。
我正在通过标志处理想要的销售,表示 0 或 1。
有一些链接可以对列表进行排序。

Most Viewed    
Wanted    
For Sale    
New Arrivals    

现在,当用户单击时,所有列表都会根据参数 i am sendig 进行排序。
我想使用 Codeigniter 的分页类。
这里出现了一些问题。
当我单击让假设想要并发送一个参数时,它会列出所有想要的产品。

Now i click on a pagination link and the wanted parameter is gone 
and the list becomes without wanted parameter.    

其他锚点也是如此。
我必须限制它,所以它仍然有我的参数。
第二个问题是我看到的 Codeigniter 正在消失。
我需要一些用户可以选择的链接。意味着我想给用户功能来选择他想在一页中看到多少产品。

Let suppose 5 ,10 ,15 ,20    

选择较大的数字将减少页数。
而且我仍然想要相同的功能。
重要的一点是我想一次性处理所有这些意味着我不想为每个锚重复我的代码。我需要专家的建议以及有关 Pagination 库的任何帮助。

4

2 回答 2

0
$seg=3
$noOfresultsToshow=$this->uri->segment('5')//use if else for by default no of results
$typeOfresult=$this->uri->segment('4'); //Most Viewed Wanted For Sale    New Arrivals
$config['total_rows'] = $countqueryresults;// mention the total rows here
$config['per_page'] = $noOfresultsToshow;
$config['uri_segment'] = $seg;
$this->pagination->initialize($config);
$data['yourvariable'] = $this->model_name->getData($config['per_page'], $this->uri->segment($seg),$typeOfresult);
$data['links'] = $this->pagination->create_links();

in your view file echo $links;

于 2012-09-26T10:52:31.697 回答
0

我已经找到了解决这个问题的方法。

我在 Codeigniter 分页库中做了两种方法

他们来了

定义了两个新变量

var $base_link  =   '';
var $per_page_link  =   TRUE;
var $per_page_array =   array();

用户可以在初始化时定义它们

$config['per_page_link']    =   TRUE;
$config['per_page_array']   =   array(5,10,15,20);
$this->pagination->initialize($config);

现在方法

public function create_per_page()
{
    $CI =& get_instance();

    $output =   '';
    $current    =   $CI->uri->segment(3,5);

    if($this->per_page_link === TRUE AND count($this->per_page_array) > 1){

        foreach($this->per_page_array as $row){

            if($current == $row){
                $output .=  $this->cur_tag_open . $row . $this->cur_tag_close;
                $output .=  ' ';                   
            }else{
                $output .=  '<a href="'.$this->base_link.$row.'/1">'.$row.'</a>';
                $output .=  '&nbsp;';
            }
        }

    }
    return  $output;
}

另一个是 create_per_page_links()。我刚刚在其中复制了 create_links 方法的代码并对其进行了修改。在 create_per_page_links() 开始时,我添加了这些额外的行。

$this->per_page =   $CI->uri->segment(3,5);
$this->uri_segment  =   $CI->uri->segment(4,1); 

但是,这仅适用于分段。我没有用查询字符串测试它。此外,如果 per_page_link 为 FALSE,则两种方法都不起作用。调用 create_per_page_links 将生成以下内容

« First  < 1 2 3 4 5 >  Last »

create_per_page 将生成以下内容

5 10 15 20  

并做了

于 2012-09-27T07:43:30.717 回答