Welcome Guest, Not a member yet? Register   Sign In
Pagination
#1

[eluser]Fero[/eluser]
Hi,

I've got some issue with base_url in pagination setup. I want to paginate the two or more weburls: http://www.fotoramik.sk/blog/kategoria/clanky and http://www.fotoramik.sk/blog/kategoria/recenzie When I set the base_url I do it this way

$config['base_url']='http://www.fotoramik.sk/kategoria/'.$this->uri->element(3);

But it's not working correctly, the base_url is "stacking up" so after few clicks, generated links tried to visit http://www.fotoramik.sk/kategoria/clanky/clanky/1 page

What do i do wrong?
#2

[eluser]TheFuzzy0ne[/eluser]
First of all, I'd imagine you'd want to be using $this->uri->segment(3), unless of course you have you're own custom URI class. Other than that, it just sounds like the problem is that you're using a relative path in your URLs, instead of an absolute path.

Please could you post the code for your controller method, as I suspect there's a bit more to it than that?
#3

[eluser]Fero[/eluser]
this is the controller's method kategoria which handles the calling of model article.php:

Code:
function kategoria()
  {
      $this->load->model('article','',TRUE);
      $this->article->header();
      $this->article->menu();
        $this->article->body($this->uri->segment(3),"kategoria");
        $this->article->footer();
  }

The third segment is "clanky" or "recenzie" (articles/reviews). "kategoria" is just to determine what kind of output we want in body. (category)

For pagination implementation I've tried to use the example from this article (http://www.devshed.com/c/a/PHP/Paginatin...Igniter/2/)

Article.php model, function body:

Code:
function body($page,$category) //page-WHERE klauzula ; kategoria - ide o vypis vsetkych clankov v kategorii?
  {

    //Logo
    $data['logo']="Fotoramik.sk";
    $data['logo_url']="http://www.fotoramik.sk";
    $data['popis_logo']="Všetko o digitálnych fotorámikoch";


    //Reklama
    $data['ad_300']='';
    //articles
    
    $this->load->library('pagination');
    
     /* This block handles different stuff */
    If ($page==""): $data['query']=$this->db->query('SELECT id,odkaz,title,picture,text,date FROM articles WHERE date<=now() ORDER BY id DESC LIMIT 3'); endif;
    If (($page!="") AND ($category=="")): $data['query']=$this->db->query("SELECT id,odkaz,title,picture,text,date FROM articles WHERE odkaz='".$page."' ORDER BY id DESC LIMIT 1"); endif;
    
    /* end of the block */
    
    If (($page!="") AND ($category=="kategoria")):
    
    // set pagination parameters
    
    $config['base_url']=''; //don't know what to put here
    $this->db->where('kategoria',$page); //counts only articles of category specified in $page var
    $config['total_rows']=$this->db->count_all_results('articles');
    $config['per_page']='3';
    $config['full_tag_open']='<div id="paginglinks">';
    $config['full_tag_close']='</div>';
    $this->pagination->initialize($config);

// create pagination links

$data['links']=$this->pagination->create_links();

If ($this->uri->segment(4)=="") {$current_page="0";} else {$current_page=$this->uri->segment(4);}//If page is not set it puts 0 to limitation



     $data['query']=$this->db->query("SELECT id,odkaz,title,picture,text,date FROM articles WHERE kategoria='".$page."' ORDER BY id DESC LIMIT ".$current_page.",3");
      endif;
    
    
    $this->load->view('body',$data);
  }
#4

[eluser]TheFuzzy0ne[/eluser]
$config['base_url'] would normally be the URL that comes before the page number. For example:
Code:
$config['base_url'] = site_url('controller/method/');

Hope this helps.
#5

[eluser]Fero[/eluser]
http://www.fotoramik.sk/blog/kategoria/clanky

Check it out - on the bottom, Why does number two referes to http://www.fotoramik.sk/blog/kategoria/clanky/3 ???
#6

[eluser]TheFuzzy0ne[/eluser]
The page number you see isn't the page number as such, but rather the result number where the page should start rendering. Say for example, you displayed 20 results page, page 1 would be 1 (as that's the first result), page 2 would be 20 (as that's the first result of the second page), page 3 would be 40, and so on.

EDIT: Basically, you should be able to use this number in your $this->db->limit() statement, but don't forget to limit the results to 3 per page if that's how many results per page you've told the pagination class you want to use.

Code:
$start_result = $this->uri->segment(3);
$this->db->limit($start_result, 3);
#7

[eluser]Fero[/eluser]
It doesn't work well, look:

http://www.fotoramik.sk/blog/kategoria/3 this is the url it tries to load after I click "2" on pagination links however there should be http://www.fotoramikl.sk/blog/kategoria/clanky/3 -> "clanky" part is missing (it's variable)
#8

[eluser]TheFuzzy0ne[/eluser]
Then you need to add the "clanky" part to your base URL.
Code:
$config['base_url'] = site_url('blog/kategoria/clanky');
#9

[eluser]Fero[/eluser]
OK, I've done that but now I got a problem with numbering and showing of the articles.

http://www.fotoramik.sk/ -> when you look here, you can see the "test" article. It's category is "clanky" however when you go to "Clanky", test doesn't show. there are pagination links but the number 2 leads to the 3rd article "Co je to fotoramik?" but test is nowhere.
#10

[eluser]TheFuzzy0ne[/eluser]
I forgot... The MySQL limit offset starts at 0, not one. So you'd need to do something like this in your model.
Code:
$start_result = $this->uri->segment(3);
$this->db->limit($start_result - 1, 3); // subtract 1




Theme © iAndrew 2016 - Forum software by © MyBB