Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Statistics
#1

[eluser]masson[/eluser]
Hey Guys,

I'm pretty new here, so bear with me... Wink.

Now!, i'm having small issues building a small Statistics app in Codeigniter and not sure how i will resolve this. I have created a new table which logs the IP of users, i am using "<?=$this->db->count_all('hits');?>" to output the number of hits but this is what i am trying to create in my app.

1. Log IP's and count total hits (solved)

2. Summarize these ip's to get the total unique hits. (not solved)

3. Output hits by each week, such as. "This week: xxx hits, last week: xxx hits" (not solved).

This is a very basic hit counter, all suggestions welcome and all help very much appreciated.

Regards,
Mitnick
#2

[eluser]nzmike[/eluser]
I had a similar problem a while ago.

With the unique hits one try using the MySQL function "GROUP BY".

MySQL - Group By

Code:
// Select each ip address once
  $query = "SELECT * FROM stats GROUP BY ip";

  // or if you wanted to see how many unique ip's exist
  $query = "COUNT('ip') FROM stats GROUP BY ip";

  // or active record
  $this->db->group_by('ip')->get('stats');

The group by week is a little trickier. It would be possible using SQL but I would probably run a Cron script once a week to summarise that weeks data. That way you can just grab the data from the "weeks" table rather than having to calculate it every time the stats page loads.
#3

[eluser]Agence de relations publiques[/eluser]
Thanks for the answer nzmike, exactly what I was looking for!




Theme © iAndrew 2016 - Forum software by © MyBB