Get $500+ of the best After Effects files, video templates and music for only $20!
CodeIgniter from Scratch Day 7: Pagination
videos

CodeIgniter from Scratch Day 7: Pagination

This entry is part 7 of 17 in the CodeIgniter From Scratch Session
« PreviousNext »

In these last two weeks, I’ve received bunches of requests for a CodeIgniter pagination screencast; so that’s what we’ll be reviewing today! As a bonus, we’ll also take a look at the super convenient HTML Table class.

Catch Up

Day 7: Pagination

Other Viewing Options

Pagination

Thank you, Screencast.com!


Screencast.com

…for providing the hosting for these video tutorials.


Add Comment

Discussion 238 Comments

Comment Page 3 of 4 1 2 3 4
  1. Steven says:

    Great tutorial jeff, how would one use this framework to show the records as blog posts rather than in a table?

  2. William Rouse says:

    Jeff:
    Please come back with more CI stuff. I am late to the tutorial and this was lovely. Please keep your promise in the first tutorial where you would develop a full web site.
    Thanks for doing this series.

  3. William Rouse says:

    One more thought.
    The one way I could get the pagination program to work is to change the line on my machine from:
    $config['base_url'] = ‘http://localhost/ci_day7/index.php/site/index;
    to
    $config['base_url'] = base_url().’?site/index/’;
    which is actually thhe same except for the question mark. I have been in the user guide for over an hour and I can’t figure this out. Where can I read about the question mark and that syntax.

  4. Walter says:

    Hi Jeff:
    I find your screencasts really usefull, I mean… FANTASTIC.
    I’d suggest ci+ajax+jquery for next one.

    Come on J.! lot of people will be more than happy to watch more from you.
    Walter

  5. Walter says:

    HI jeff,
    The link for this screencast is not working. Same is happening for day-6 too.
    Can you restore it?
    Thanks
    Walter

  6. Rich says:

    Two months since last CI tutorial, guess it’s officially DOA. :( I’ve enjoyed these and they have helped me take my coding to the next level. Thanks Jeff.

  7. Grimm says:

    Thanks for the excellent tutorials!
    To my best regret links for last two – 6 and 7 are broken.
    Anyway, after long search in www, I found out Day 7 –

    http://blip.tv/file/2670407

    Unfortunately, I couldn’t find Day 6.

    Jeff, please – Christmas is coming, make us a present and restore Day 6 and 7 :)

    Best Regards

  8. Ben says:

    Come on man – don’t stop them now – you said you’d do 10 days…

    If these have stop you could at least say so?

    Thanks have really enjoyed them.!

  9. Adi says:

    Thank you Jeff,
    I just created a site for a client using codeigniter which i learned from your tutorials.
    You’ve helped me a lot.

    Thanks again.

  10. Mark says:

    Thanks Jeff for these, hope you will continue with it !

    For those looking for Day 6 and Day 7 you can download them from Rapidshare.

    http://rapidshare.com/files/318456608/nettuts_codeigniter_day6.zip

    http://rapidshare.com/files/318603335/nettuts_codeigniter_day7.zip

  11. Mark says:

    For those looking for Day 6 and Day 7 you can download them from Rapidshare.

    http://rapidshare.com/files/318456608/nettuts_codeigniter_day6.zip

    http://rapidshare.com/files/318603335/nettuts_codeigniter_day7.zip

    Jeff thanks for these great tutorials, hope you will continue with them !

  12. Walter says:

    rapidshare links are just from premium users….

  13. Mini0n says:

    The next chapter of this series would be a great Christmas gift… ^_^

  14. Jerin says:

    I have not got a codeigniter pagination that shows the uri segment as 1 for the first page,2 for second page and so on…. Instead using Codeignitr pagination the url is offset by 1. ie: its showing 1 for the secnd page, 2 for the 3rd page and so on….

    Can u please give me a code so that i can do this.

  15. Fábio Antunes says:

    I’ve enjoyed your tutes, specially about Code Igniter, they’re really great.

    I haven’t had the chance to go around all of them, but once you encourage comments and tute proposals for this series. I have one :=D

    Could you do one, about the benefits about the URL system/class in place with Code Igniter, but most of all how to use them wisely.

    It would be really great.

  16. jason says:

    Just wanted to add in how awesome these tutorials are.. You totally make CI and MVC a joy to work with!

    thanks!

  17. woony says:

    is there a day 8 , 9 and 10 coming???

  18. MSylvia says:

    Wonderfull tutorials! I agree more on this subject would be great.

  19. Radi says:

    Thx Very Good Tutorial! Keep going! =P

  20. Tom Van Assche says:

    Please continu this great series!

  21. eric says:

    Please more CI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  22. David Fitzgibbon says:

    Yeah more Codeigniter!

    Even just a quick tip on how to get rid of the index.php, havent gotten a hacj to work yet!

    • Dave says:

      1) Create .htaccess in the root of your app – where the main index.php is

      2) paste this into it:
      DirectoryIndex index.php
      RewriteEngine on
      RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

      3) Ensure mod_rewrite is installed/running on Apache

      4) Ensure Allowoverride is set to ALL (“Allowoverride All”) in Apache settings (should be “httpd.conf” in Apache, “000-default” in the ‘sites-enabled’ folder in Apache 2)

      SHOULD work. I had a bit of trouble because I had forgotten that I had a second set of apache config files for SSL, but after I changed Allowoverride in that, it was golden…

      • Joey says:

        Thank you!

        Finally got to the point where my uri->segments were blank, only solution was a bad ModRewrite. Thanks for your ModRewrite, works straight away!

  23. Vladan says:

    Is it possible to see a chapter 8 in near future? Your tutorials are very helpful for learning CodeIgniter.

  24. emcgfx says:

    Maybe you could do some more database tutorials for CodeIgniter from Scratch Day 8 I would like to see how to store categories in database, show then on page with pagination. Then results under those categories with pagination support also. Thanks.

  25. alex says:

    i am in need of another Codeigniter day :)

  26. Alexander says:

    Hay Jeffrey I was wondering if you would consider doing a tutorial on dynamically loading pages, like in a blog where you have one source file that gets a page id and loads the data. I know how to do it in php but i do not know how to approach it using MVC.

    –thanks!

  27. eric says:

    I swear you miss one F’ing character and you can piss away hours of time……

    I am learning though. The hard way………

  28. MJB says:

    I moved to new host and messed up CI layout format. Didnt change anything, can someone email me what happen is it server permissions? See at http://www.teacher-x.com

    THANKS

  29. Kasper says:

    Really nice tuts and learned a lot from them, but I was thinking if there isent another way to do this, because this way I don’t really know how to tamper with the actual results, set I only want to show 100 chars of the content part? I know there is a way to change the layout of the table to divs, but it would be really nice with a chance to tamper the actual data.

  30. Thim says:

    Awesome tut as always Jeffrey!

    Realley helped me :)

  31. saad says:

    but if we won’t display the id , how can we do this ?

  32. Miki says:

    Greetings from Serbia! Thank you for your lessons that contribute to the development of better web applications!

  33. Jason says:

    I’m having an issue with the pagination and the routes.php file. Can you retain the clean URLs? I have to put in the full url in the base_url config parameter, so the subsequent pages are much longer than the others.

    And I had to use rsegment rather than the simple segment. It works now, but with the ugly URLs.

    Could there be another AJAX pagination solution where the URL itself doesn’t change?

  34. Nikhil says:

    Hi i love the CI series ..plzzz keep them coming..I had a question ..im working on a similar project but i need the table data to be links..for eg with this case i need each of the title and content to be links …is that possible ??please help!!

  35. Dave says:

    @Jeffrey Way: “what did that take us – just a few minutes?” – a little longer, I’m using a MSSQL database :P
    Up to this point, the series has been perfectly compatible with MSSQL, this one is a little more involved due to MSSQL’s lack of the OFFSET feature (so essentially, active records just spits out the query “select top 10 * from data” as it’s MSSQL driver has no idea what to do with the OFFSET clause we specified in get(). Instead, a little ingenuity has to be forged using MSSQL’s BETWEEN clause.

    For anyone interested, here’s the resulting code for the Site class using MSSQL + pagination…
    http://codeigniter.com/forums/viewthread/55934/#734541

    :)

  36. piker says:

    How does it pagination works with custom query ?
    $this->db->query(‘ SELECT * FROM table JOIN table2 WHERE table.id = table2.id_table2 ‘);

    I don’t want to run two queries to make a pagination.

    • harman says:

      in controller:

      $config['base_url'] = base_url().”admin/users/index/”;
      $config['total_rows'] = $this->db->count_all(‘yourTableName’);
      $config['per_page'] =10;

      $this->load->library(‘pagination’);
      $this->pagination->initialize($config);

      //load the model and get results
      $this->load->model(‘admin/user_model’);

      $data['dloop'] = $this->user_model->getContentPage($config['per_page'],(int)$this->uri->segment(4));

      echo $this->load->view(“admin/news_view”,$data,true);

      in MODEL:

      function getContentPage($num, $offset){

      $sql_q=”SELECT * FROM table JOIN table2 WHERE table.id = table2.id_table2
      ORDER BY table.id
      Limit $offset,$num”;

      $query = $this->db->query($sql_q);
      return $query->result_array();
      }

      in View :

      pagination->create_links(); ?>

  37. Khalil says:

    Dear Jeffrey Way,

    Please give me solution…

    CI Pagination Problem:

    my URL is http://www.myDomain.com/myController/myFunction/passingRowID/paggination

    pagination is not working correctly with “segment(4)”

    waiting for reply…

    Thank you.

  38. Newicz says:

    Hi guys!

    I have question about table library i have something like this:

    $this -> db -> select (‘id, title, made_date, auth, menu_item’);
    $query = $this -> db -> get (‘pages’);
    return $this -> table -> generate($query);

    And it is working, it gives me a table with pages in database, but i would like to add 2 columns (edit and delete) how can i do it, can anyone help me?

    thanks in advise!

  39. Tahsin Hasan says:

    Hello,

    see how to use page specific layout design for codeigniter on http://newdailyblog.blogspot.com/2010/06/creating-page-specific-layout-in.html. Thanks.

  40. adelle says:

    That is a great tut .
    But i have a question , what should i do if i wanted to make the info inside the table dynamic such putting an anchor link ?

  41. Roee A. says:

    Whenever your code is inside a folder inside the controller, the pagination will make some problems recognizing on which page you are.
    use $config['uri_segment] = X if the segment is not 3. :)
    It solved me a lot of problems.

    • Cameron Malek says:

      Thank you so much! I’ve been looking for a solution to this problem for 30 minutes now. You’ve saved me so much time!

  42. ci9 says:

    Another very nice Tuts again by Jef_way.

    I love you, i love you Jef you are my idol. LOL :)

    -ci9

  43. Skot says:

    I have greatly enjoyed these tutorials on Codeigniter, however, I am unable to view the video for this tutorial, Day 7. I have attempted it via online, download, and iTunes to no avail. The download leads me to the Screencast site, but states that the page is 404. Please help.

  44. Alfredo says:

    The first link is not available….the flv version function good.

  45. Side says:

    Is it just for me or the video isn’t loading for others too?

    I waited for like 5 mins to load and nothing, why?

    Or if its possible could you please re upload it?

    i would be really happy, ty

  46. Matt says:

    Hi Jeff,

    Why did you use jQuery to apply the table striping? Any reason not to use straight CSS?

    tr:nth-child(odd)

    - Awesome tutorials tho BTW. I’m loving them! Looking forward to some help with CI and shopping cart payment gateways.

    Thanks again,

    Matt

  47. Rohit says:

    Hi Jeff & Burak,
    Thanks a lot for such a great videos! I am a web developer newbie. I had never heard of codeigniter before. After watching only few of your videos, I could write simple code.

    one question -what is that tool which you use for writing CSS with live preview?

  48. meltz says:

    I learnt how to create web application from scratch just by watching this codeigniter series, before this I have 0 knowledge about codeigniter framework.

    Really love your tutorials, the screencast are so simple and clear. Keep up the good work !

Comment Page 3 of 4 1 2 3 4

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.