Welcome Guest, Not a member yet? Register   Sign In
Post view count in codeigniter blog

I am new in codeigniter and php.

I have a blog and i want count post view for creating popular post plugin.

Please help me.


So if i under stand you correctly this should be exactly what you need to do.
First grab the data from the data base in the model like below. Then pass it on trough to the controller then run a foreachloop to get the number of post hope this helps.If you still dont under stand it private message me here and i can come and help you on Skype or something.

for extra documentation here is the link to the docs for the num_rows


This is your model
public function get_rows(){
$rows = $this->db->get('your table name here');
        return $rows->num_rows;

Okay, so if you have your blog already up and going it's real easy.

In your "view post" controller function, before you get the blog post details from your DB like you normally do. Then simply call a new model function that increments "view_count" for that blog. Then get your blog post details and it will have the correct count.

One line of code in your controller, one new small model function (max 8 lines of code, plus function comments).

Obviously you'll need to create a new DB column (view_count) in your blog post table.

Things get a bit more tricky if you don't wan't the count to increment if admin/author views the post, but even that's not too bad.

Post some code if your stuck.

Theme © iAndrew 2016 - Forum software by © MyBB