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 1: Getting Started With the Framework
- Day 2: Database Selecting Methods
- Day 3: Sending Emails
- Day 4: Newsletter Signup
- Day 5: CRUD
- Day 6: Login
- Day 7: Pagination
- Day 8: AJAX
- Day 9: File Uploading and Image Manipulation
- Day 10: The Calendar Library
- Day 11: File and Directory Operations
- Day 12: Shopping Cart
- Day 13: Extending the Framework
- Day 14: Security
- Day 15: Profiling, Benchmarking & Hooks
- Day 16: Displaying & Sorting Tabular Data
Day 16: Displaying & Sorting Tabular Data
Thanks for watching! Any questions/thoughts?

these things can be done with javascript, but good to know :)
Yes that can be done with JS but if thats a huge amount of data then the page load would be higher too. Unless you’d use Ajax to load data.
I agree. When you have huge amounts of data, server-side sorting is deemed better. See Google and eBay etc.
You guys are like the best thing since the invention of slice bread.
+1
Just a little tip, insted of using the COUNT(*) you can use this:
$this->db->count_all();
Why is that better?
Only if you want to count all rows in a table. Once you start adding search functionality, and using where clause (which should be on the next episode), you can’t really use that anymore.
In this case is better count(1) that count(*). Is a optimization in SQL world. Thank Burak (and Jeffrey too)
CodeIgniter has its own num_rows() function that you can use – $this->db->query()->num_rows(); (http://codeigniter.com/user_guide/database/results.html). It gives you access to the number of rows returned by your query without requiring anything special. It should be called after get(), but before result().
Great tutorial! I’m with mikky :)
And what if this form also needs to be also searchable? What would then url`s look like?
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
Great tutorial, Thank you!
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.
Thanks! Great tut.
BTW, the direct link to video:
http://blip.tv/file/get/NETTUTS-CodeIgniterFromScratchDisplayingSortingTabularData289.m4v
Thanks Burak! Big fan of your tutts!
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 :(
Any chance of a non-video version, even if its just the code snippets?
Any link to download the video ?
Thanks.
You can download all the videos at nettuts.blip.tv by looking for the “Download” link at the bottom of the page.
http://blip.tv/file/get/NETTUTS-CodeIgniterFromScratchDisplayingSortingTabularData289.m4v
Yet we aren’t allowed to neatly sort these and torrent them… because.. that would……… Well, we aren’t allowed anyway.
wow! thanks :) love your tuts!
….ps: please please a tut on php debugging would be great :) xdebug have a good integration with aptana :)
Nice tutorial, I’m always following, thanks!
Please make tutorial about templating using codeigniter
JShway kinda covers that in his login tut: http://a44.video2.blip.tv/5870002834299/NETTUTS-CodeIgniterFromScratchDay6219.mp4?bri=24.4&brs=590
this is a pretty good templating system: http://maestric.com/doc/php/codeigniter_template
I mean templating using Parser.
Like
{title}
{entry}
{title}
{content}
{entry}
please give some tutorial about cakephp. by the way nice post. I really enjoyed it.
Chris Coyier over at CSS-Tricks.com started dabbling in CakePHP. Maybe you could convince him to do more?
http://css-tricks.com/cakephp-project-events-manger/
Thanks! :-)
The series is really rocking.
I hope a detail tutorial on SAAS application using CodeIgniter will come next.
Thanks for taking the time to produce a quality tutorial.
Is there any way to download all of these for offline viewing?
-Henry
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 :)
Excellent tutorial, very well presented and covering everything I wanted to know about pagination with table data display!
Thank you for your hard work.
Great tutorial on CodeIgniter.
Please upload the code as attachment for downloading.
Thanks for sharing.
http://nettuts.s3.amazonaws.com/786_ci/ci_series_day16.zip
Awesome tutorial..
Any one can begin with this series to learn CI easily..
Thanks for posting
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).
where can I find the sourcefiles?
Click the button that says “Download Source Files” on top of the article.
hi Burak Guzel
excellent but i want to download this video if possible then post like thru reply
Thanks Burak
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;
It seems some links of this tutorial are broken !
Could you please check it ?
great series.
does jeffery has stop the php series or not it is pending
I want to download this video if possible then post like thru reply .. Thanks…
@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)
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.
What if this form also needs to be also searchable? What would then url`s look like?
That’s the next episode.
Burak,
Thanks for the great tutorials. When can we expect the next episode? I could really do with it about now! ;)
Excellent tutorial, very well presented.
Thanks.
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.
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.
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
There is no user input variable in that select clause, so it’s not a security risk.
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.
Excelent video, thanks! What about Kohana framework tutorials?
I would like to learn Kohana too, but I keep hearing the documentation is a bit lacking.
thank you burak
but i think it will be nice if you show us how to use jquery with codeigniter
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
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.
Thanks.. I think it will be nice if you show us how to use jquery with codeigniter..
Can you do debugging of CodeIgniter in Aptana ?
Debugging could be a GREAT addition to this series.
Great video, thanks!
Can you post the database fields??
Never mind ;)
What about the next day (day 17)?
Maybe working with different languages would be a great next topic for a CI-tutorial?
Good work!
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…
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.
Burak, thanks a million. Seriously good stuff. Keep it coming!
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.
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.