Welcome Guest, Not a member yet? Register   Sign In
Hit Counter for items
#1

[eluser]jjimenezweb[/eluser]
Hi,

I am new to Codeigniter, and not very well as it is all about.

I would like to make a hit count for a few items that I have on my site.

If someone has already done or can give me some guidelines to do so would appreciate a lot.

View + Controller + Models

Regards,
#2

[eluser]CroNiX[/eluser]
This would be pretty simple. On the pages you want "counted", just have an update query in the controller that loads that page that just increments a "views" column in the db table. It's just a simple query, that could easily be placed in a model.

The query would just be something like:
Code:
$this->db->where('page_id', $page_id); //however you are storing your page identifier
$this->db->set('page_views', '`page_views`+ 1', FALSE); //increment counter where page_views is an INT with default value of 0.

Another solution is to just use google analytics, which automatically does this and tons more.
#3

[eluser]jjimenezweb[/eluser]
To implement this, I have to create a new function or I can put it in any function already?
#4

[eluser]CroNiX[/eluser]
However you want. If you're going to be using it in a lot of places, I'd make a library or helper so you can just reuse the code instead of copying it all over the place.
#5

[eluser]jjimenezweb[/eluser]
So I have my code in the model.

Code:
public function set_hits($id){
$this->db->set('property_hits', '`property_hits`+ 1', FALSE);
$this->db->where('property_id', $id);
$this->db->update('property');

}




Theme © iAndrew 2016 - Forum software by © MyBB