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?

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.okadadesign.no/blog shin

    Just for your note. Using file name like Film_model.php does not work in Ubuntu/Linux. It is better to use all lower case like film_model.php. I think it is better to use lowercase for all the file names.

  • http://www.buzzednow.com BuzzedNow

    i think most of us use all smaller case for filenames. I’ve finished my codeigniter tutorial and this site really contributed to all of my knowledge. I have a site now based on this 13 days of codeigniter, just click on my link.

    I know it still has a long way to go, but as a newbie starting from scratch i think i did a pretty decent job.

  • Dan P

    Was this the end of CI from scratch?

    I wish you guys would edit the earlier articles in the series with the full list of tuts, so when I’m at day 6, I can click on day 7 right from it. Or day 13 if I feel like it. At least that way I can see how far it goes.

    thanks!

  • chavewain

    How i can convert a DATE before print in the table

    please help me

  • Koen

    Excellent! Just what I needed! Cheers!!
    Looking forward to more in these series.

  • Franklin

    Exellent episode keep on working in this kind of tutorials that help us a lot.

    thank you very much.

  • subdesign

    Hi,
    With Firefox 4.0 the down arrow icon at sorting has strange characters before. I have five small squares, 0081 number inside them. Somebody saw that? Who knows why?

  • http://nourl nachkata

    There is no green DIV with information about the next tutorial :)

    I love this tutorials!!! It`s great and very helpful!

  • Annie

    thank you so much.. you really help me to learn codeigniter.. thanks a lot

  • Giorgio

    Hello Burak, thanks for your tutorial …
    I’ve see that if you are in any page, if you click on a title to change sorting of column, it all comes back to page 1 … The segment (5) page does not take … then I tried to do this:

    <?php foreach($fields as $field_name => $field_display): ?>
    <th <?php if ($sort_by == $field_name) echo “class=\”sort_$sort_order\”" ?>>
    <?php echo anchor(“films/display/$field_name/” . (($sort_order == ‘asc’ && $sort_by == $field_name) ? ‘desc’ : ‘asc’).”/”.$this->uri->segment(5), $field_display); ?>
    </th>

    In this way, is functioning, but the question is: is this the correct way?

    Thanks

  • juampick

    Hi!! Thanks for yours tutorials! I watched almost in a week! I’m learning a lot! I’m from Argentina but your english is very well so I can understand! :)

    I have a doubt… Why don’t you use “table” library? like in day 6: Pagination? These advance functions don’t work on that library so you have to make the table manually??

    Thanks again!

    JP Cook

  • phuong

    videos not watch. Help me

  • http://ladolomidze.com Lado

    Hey Burak!

    I’m using Aptana Studio (ver. 3) too, and how did you do that, when you typed “html:5″, it converted a blank HTML5 template?

    • http://ladolomidze.com Lado

      Oh! I found it, Zen Coding! : )

      • Ian

        Lado,

        If you come back here and read this, I don’t see a version of zen coding for aptana. Is it at google here where you found it? http://code.google.com/p/zen-coding/downloads/list

        I see one for about every ide and editor except for aptana.

        I know there is a way to add snippets to a bundle.rb file but when I looked in the aptana files I found about a thousand bundle.rb files and the instructions I had at the time assumed I was a mind reader and new which one they were talking about. :-)

        I’m currently using notepadd++ and/or gedit depending on the OS and they both have a snippet plugin that comes with them and just has to be added in the plugin manager.

        Thanks

  • visionecreativa

    Great tutorial… thanks

  • Ian

    Great tutorials Burak! Thank you!

    I’ve been using notepad++ for all of these tuts when on my win7 and gedit on Ubuntu laptop. Something I haven’t seen since I used it once a few years ago was character map and it was in MS Word. I figured out I can use all the online utf-8 characters if I switch notepad++/gedit to use utf-8 encoding and it works since it is a web standard. So I learned something new.

    I’m not sure about the comments on uppercase names because I haven’t had a problem on win with IIS or on Ubuntu with Apache. Both are running php5.

    I notice in CI (at least in the recent version) all the library files and class names are capitalized like you have been doing.

    Also this is more in line with naming conventions like Zend (Zend_Controller_PluginAbstract) except that they change the prefix to “Zend” instead of “ZEND”

    I think it’s a good idea to put restrictive naming conventions like all class names start with a prefix or all class names start with a capital letter. This ensures that if someone has to make a change in the core it won’t break everything. It makes things more specific and certain. IMHO

  • Patryk

    Thanks for these great tutorials, Burak!

    I have a quick question, shouldn’t we use htmlspecialchars() in order to escape the output from the database?

  • fanch

    Hi Barak!

    Thank for your fabulous tutorials…

    I have a problem with the pagination links but I can’t figure out why. Here is the code:

    Hello!

    i’m too new to CI to prentend having ancounter a bug. There’s must be a mistake in my code! I’ve read documentation and browsed forums but i can’t find where!

    Any help is welcome:

    I want to a simple pagination with sorting features. Here is the code:

    load->model(‘project_model’);

    $results = $this->project_model->search($limits,$offset,$sort_by, $sort_order);
    $data['projects'] = $results['rows'];
    $data['num_results'] = $results['num_rows'];

    //pagination
    $this->load->library(‘pagination’);
    $config = array();
    $config['base_url']=site_url(“projects/display/$sort_by/$sort_order/$offset”);
    $config['total_rows'] = $data['num_results'];
    $config['per_page'] = $limits;
    $config['uri_segment'] = 5;

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

    $this->load->view(‘projects’,$data);

    }

    }
    ?>

    The search function works great, i can type url such like:

    http://10.153.9.6/dev/index.php/projects/display/id/desc
    http://10.153.9.6/dev/index.php/projects/display/id/desc/10
    http://10.153.9.6/dev/index.php/projects/display/counrty/asc/400
    http://10.153.9.6/dev/index.php/projects/display/name/asc/11

    But the pagination links are wrong, I obtain:

    http://10.153.9.6/dev/index.php/projects/display/id/desc/0/240

    instead of:

    http://10.153.9.6/dev/index.php/projects/display/id/desc/240

    I thought the problem was in the “uri_segment’, but I think 5 is the correct value:

    I’ve missed something. Any idea?

    thanks!

    fanch

  • dominique

    thank a lot. You help me to learn codeigniter.

  • Adnan

    Hello,

    it is really good working in CodeIgniter 1.7 version. And now i am using CodeIgniter 2.1 version or latest version. it is not working and i got error message. it says:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined property: Films::$pagination
    Filename: controllers/films.php
    Line Number: 30

    Fatal error: Call to a member function initialize() on a non-object in C:\XAMPP\HTDOCS\Ci_test\application\controllers\films.php on line 30

    Can you solve this problem?
    Thanks

  • Adnan

    Hello,

    it is really good working in CodeIgniter 1.7 version. And now i am using CodeIgniter 2.1 version or latest version. it is not working and i got error message. it says:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined property: Films::$pagination
    Filename: controllers/films.php
    Line Number: 30

    Fatal error: Call to a member function initialize() on a non-object in C:\XAMPP\HTDOCS\Ci_test_2_1\application\controllers\films.php on line 30

    Can you solve this problem?

    Thank you

  • Alex

    One of the best Codeigniter tutorials. Great job man. Now I know how to sort search results with a link. However, how can I get the same results using select’s onchange() event and reload the page with sorted results. I really need to find out how to make it for my new project. But I couldnt find anything like that on internet. The problem is that I dont know how to make javascript (jQuery) to work PHP in this situation (I know how to make it with AJAX, but I dont want to use it here because I want the page reload after select’s onchange event fires). Please help me guys. I would really appreciate your help. Thanks.

  • http://www.keerthi.me Keerthi

    Thank you very much. Helped me a lot.

  • Richard Frostick

    I’d like this series to be updated for codeigniter 2.0+ and the HMVC addon. Thanks for the work you do.

  • Kara Murat

    This is a really good document.Thanks for sharing…
    (Bir de türkçesi olaydı,ingilizce sorunu olanlar için iyi olurdu :))

  • Shone89

    Hi, thank you for the great tutorials !
    Can you make one multi-language CI application ? I think that would be great tutorial.

  • Ej

    hi… i was doing this tutorial and when i tried to run it. i got some errors. then i posted it here http://stackoverflow.com/questions/16635266/a-php-error-was-encountered-undefined-variable they say it was too localized. what does this mean. and how can i solve my problem.