CodeIgniter from Scratch: Displaying & Sorting Tabular Data

CodeIgniter from Scratch: Displaying & Sorting Tabular Data

Tutorial Details
  • Topic: CodeIgniter
  • Difficulty: Intermediate
  • Tutorial Format: Video

In today’s video tutorial, we are going to use CodeIgniter to pull information from a database and display it in a sortable table structure. This is a quite common task, especially inside admin areas, for displaying database records. We’ll be utilizing a few different utilities, such as the active records library and pagination.


Catch Up


Day 16: Displaying & Sorting Tabular Data

Day 16: Displaying & Sorting Tabular Data

Thanks for watching! Any questions/thoughts?

Add Comment

Discussion 91 Comments

Comment Page 1 of 21 2
  1. Yoosuf says:

    these things can be done with javascript, but good to know :)

  2. mikky says:

    You guys are like the best thing since the invention of slice bread.

  3. Just a little tip, insted of using the COUNT(*) you can use this:
    $this->db->count_all();

  4. Стоян Киров says:

    Great tutorial! I’m with mikky :)

  5. Andrew says:

    And what if this form also needs to be also searchable? What would then url`s look like?

  6. Raul says:

    Hey guys.

    I really like these tutorials, but … these are for CI newbies, but for them are GREAT.
    What i want to ask you is: why all tutorials use the view library and not the parser ? I can give you examples or make a video about it. I think the Parser class is better for programming.

    What do you think ? What’s the best ? The View or the Parser ?

    Thanks,

    Raul

  7. Khalil says:

    Great tutorial, Thank you!

    • Khalil says:

      Dear Burak Guzel,

      I really want to learn about Codeigniter’s URI-Routing and Output Class. Please let us learn with your great “CodeIgniter from Scratch” series.

      I am requesting you please give us your screen-cast. I will be waiting for your reply – Thank you.

  8. Thanks Burak! Big fan of your tutts!

  9. Sz-Media says:

    Hey Burak, another great Tutorial! Can you explain the templating with code igniter in your next tutorial?
    I mean, when you have classes like login and latest news. how to integrate them to the main site with header, navi, content and a sidebar with login and latest news ?! thats the point i got stuck with :(

  10. Brian says:

    Any chance of a non-video version, even if its just the code snippets?

  11. Brayan says:

    Any link to download the video ?

    Thanks.

  12. erminio ottone says:

    wow! thanks :) love your tuts!

    ….ps: please please a tut on php debugging would be great :) xdebug have a good integration with aptana :)

  13. Nice tutorial, I’m always following, thanks!

  14. Sapono says:

    Please make tutorial about templating using codeigniter

  15. IT Village says:

    please give some tutorial about cakephp. by the way nice post. I really enjoyed it.

  16. Thanks! :-)
    The series is really rocking.
    I hope a detail tutorial on SAAS application using CodeIgniter will come next.

  17. Henry says:

    Thanks for taking the time to produce a quality tutorial.

    Is there any way to download all of these for offline viewing?

    -Henry

  18. Brad says:

    Excellent tut Burak, this one gets deeper into the mist. Will the code be available for download? I hate to be the only one NOT begging for something :)

  19. Carl Walker says:

    Excellent tutorial, very well presented and covering everything I wanted to know about pagination with table data display!
    Thank you for your hard work.

  20. Jaspal Singh says:

    Great tutorial on CodeIgniter.
    Please upload the code as attachment for downloading.
    Thanks for sharing.

  21. Awesome tutorial..
    Any one can begin with this series to learn CI easily..
    Thanks for posting

  22. Kestutis says:

    Great series, Burak.
    For this task there is also a great plugin on http://www.datatables.net/. And it’s working well with codeigniter (I tried by myself).

  23. Natrium says:

    where can I find the sourcefiles?

  24. webcorsa says:

    hi Burak Guzel

    excellent but i want to download this video if possible then post like thru reply

    Thanks Burak

  25. Lucho says:

    Quick tip: you can use $ $q->row() instead of using a tmp variable to get the first row from $q->result().
    So it can be just $ret['num_rows'] = $q->row()->count;

  26. Omid says:

    It seems some links of this tutorial are broken !
    Could you please check it ?

  27. irfan says:

    great series.

    does jeffery has stop the php series or not it is pending

  28. I want to download this video if possible then post like thru reply .. Thanks…

  29. erminio ottone says:

    @burak is that aptana studio 3.0 beta? how do you feel it? better/bug free than 2.0 ? (i saw you switched to netbeans for some time than returned to aptana, that means in someway you still prefer aptana)

    • Burak says:
      Author

      Nah, it’s still Aptana 1.5
      I use it because I like the FTP sync manager, and I need it for a lot of my projects.

      I will give Aptana 3 beta a try again, since they keep updating it. Last time I tried it, PHP wasn’t fully implemented yet.

  30. What if this form also needs to be also searchable? What would then url`s look like?

  31. Excellent tutorial, very well presented.
    Thanks.

  32. Brad says:

    Hey Burak,

    In the model you have on your line 8

    “$sort_by = (in_array($sort_order, $sort_columns)) ? $sort_by : ‘title;”

    Shouldn’t that be

    “$sort_by = ( ! in_array($sort_order, $sort_columns)) ? $sort_by : ‘title’;”?

    If you say its “in_array” you will sort all columns based on the title in my use with this tut.

    • Burak Guzel says:
      Author

      This is the line:
      $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : ‘title’;

      Basically $sort_columns contains all acceptable values for $sort_by. If $sort_by is in that array, it is assigned back to itself (so it isn’t changed). Otherwise, it is assigned ‘title’, because that is the default sort_by value.

      • Brad says:

        I see, when I used it that way it would only sort according to the title column, all sort links worked but they would not sort properly(used the title as the lead sort in all rows). So I changed it to what I wrote and it worked fine. Sorry!

        One other question, when you use FALSE and remove the backticks on a query, are you sacrificing security? Model like 17 on my file

      • Burak says:
        Author

        There is no user input variable in that select clause, so it’s not a security risk.

  33. Yoosuf says:

    to be honest, when you guys are posting the Code, seriously we never work or Try out, but when without code we do search and find for more resource, so always better not the add the code along with the video.

  34. daniel says:

    Excelent video, thanks! What about Kohana framework tutorials?

  35. Mr-h says:

    thank you burak
    but i think it will be nice if you show us how to use jquery with codeigniter

  36. cagatay says:

    you used this lines

    $config['base_url'] = site_url(“films/display/$sort_by/$sort_order”);
    $config['uri_segment'] = 5;

    i want to know about offset

    when i tried this url “films/display/20″ will i get error?

    thanks burak

  37. roarbb says:

    Hi Burak. This tutorials are really great. Thanks.

    What about make tutorial about template system for codeigniter? Maybe some template library or so. It will be great and usefull for many of us. Thx.

  38. maç oyna says:

    Thanks.. I think it will be nice if you show us how to use jquery with codeigniter..

  39. Flavio says:

    Can you do debugging of CodeIgniter in Aptana ?

    Debugging could be a GREAT addition to this series.

  40. myles.b says:

    Can you post the database fields??

  41. Petar says:

    What about the next day (day 17)?

  42. Pellens says:

    Maybe working with different languages would be a great next topic for a CI-tutorial?

    Good work!

  43. bati says:

    I agree with Pellens on this one. I think multi-language CI application would be much appreciated by CI followers… awesome series by the way…

  44. Lars says:

    Great tutorials!
    Could you please write a tutorial about template system for codeigniter?

    i need a example how i create a template for using

    Header and Footer and Menu on every page.

  45. Ross says:

    Burak, thanks a million. Seriously good stuff. Keep it coming!

  46. Dan LaManna says:

    Gotta say these tutorials are absolutely great, I learned alot from knowing absolutely nothing with the framework. However one thing I’ve yet to become clear on is how to actually make a full fledged website with codeIgniter, what models/controllers I would use, etc.

  47. Ross says:

    Two tips.

    1: If you are sorting on a mysql enum field, the sort clause will not return correctly sorted records UNLESS you have created the enum field with the options already in alphabetical (and I assume, numeric) order. I had this problem, changed my enum order, and it works fine.

    2: to use the solid up or down triangle as Burak does, you can use the unicode in your CSS.

    .sort_asc:after{
    content:”\25B2″;/** unicode arial for up arrow **/
    }
    .sort_desc:after{
    content: “\25BC”;/** unicode arial for down arrow **/
    }

    I had trouble copying and pasting from the XP character map, but the above works fine.

Comment Page 1 of 21 2

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.