CodeIgniter Forums
Update Link Visits - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Update Link Visits (/showthread.php?tid=21419)



Update Link Visits - El Forum - 08-09-2009

[eluser]lotec[/eluser]
What is the simplest way to implement link visit counter within ci? I've done it before by passing link id to function that handled db entry and then redirected. A little confused in how to do it within ci framework. Nothing overly fancy, just want to know how many times a link has been clicked...simple as that, no ip, etc...


Update Link Visits - El Forum - 08-09-2009

[eluser]David Johansson[/eluser]
You could do the same as before, but put the function in a calss in a model.


Update Link Visits - El Forum - 08-10-2009

[eluser]Phil Sturgeon[/eluser]
Something like:

Code:
function add_visit($id) {
        $this->db->update('links', 'visits = visits + 1', array('id' => $id));
        return ($this->db->affected_rows() > 0);
    }

That will update it by 1 and give you a true/false response over whether or not it actually did anything.


Update Link Visits - El Forum - 08-10-2009

[eluser]jcavard[/eluser]
[quote author="Phil Sturgeon" date="1249911398"]Something like:
Code:
return ($this->db->affected_rows() > 0);
[/quote]

that's clever. I like that


Update Link Visits - El Forum - 08-10-2009

[eluser]jcavard[/eluser]
[quote author="Phil Sturgeon" date="1249911398"]Something like:
Code:
return ($this->db->affected_rows() > 0);
[/quote]

that's clever. I like that


Update Link Visits - El Forum - 08-10-2009

[eluser]lotec[/eluser]
Thanks Phil, that's what I'm talking about. Nice