php - MySQL - Count all article visitors based on their IP address and access timestamp -
i've got table filled each user's access. 1 line 1 access. in each row there field id, timestamp, ip_address, article_id,...
now, problem application used logging users can't modified me, adds 3 rows instead of 1 - logging not desired article 1 on left , 1 on right (based on article_id).
i want count article visits eliminating ballast around. how can that? overall need count in middle row's article_id access leave surroundings out.
my original idea have php function (but open ideas):
$logged_article_ids = $wpdb->get_results("select article_id " . $table_name . " group article_id", array_a); foreach($logged_article_ids $article) { // count in each visit if ip , timestamp unique or if in middle of 3 lines equal ip , timestamp. }
thank help.
update based on comments: article_id unique in entries? no, not. suggested here sample structure:
+---+-----------------+-------------+------------+---- |id | time | ip_address | article_id | etc.. +---+-----------------+-------------+------------+---- | 1 | 22-3-2015 11:00 | 134.3.4.104 | 43 | | 2 | 22-3-2015 11:00 | 134.3.4.104 | 34 | | 3 | 22-3-2015 11:00 | 134.3.4.104 | 12 | | 4 | 22-3-2015 11:00 | 32.3.42.203 | 12 | | 5 | 22-3-2015 11:01 | 32.3.42.203 | 43 | +---+-----------------+-------------+------------+----
in above table desired behaviour count middle line article of same ip_address , time in , other standalone lines. in case articles 34, 12 , 43 have each 1 visit while leaving out article 43 , 12 ip: 134.3.4.104 @ 22-3-2015 11:00. if time or ip different, this:
+---+-----------------+-------------+------------+---- |id | time | ip_address | article_id | etc.. +---+-----------------+-------------+------------+---- | 1 | 22-3-2015 11:00 | 134.3.4.104 | 43 | | 2 | 22-3-2015 11:24 | 134.3.4.104 | 34 | | 3 | 22-3-2015 11:24 | 32.3.42.203 | 12 | | 4 | 22-3-2015 11:24 | 32.3.42.203 | 12 | | 5 | 22-3-2015 19:30 | 32.3.42.203 | 43 | +---+-----------------+-------------+------------+----
article 43: 2 visitors, 34: 1 visitor, 12: 2 visitors
i thought of adding additional variable above foreach cycle remember last cycle's timestamp , ip_address. way go haven't been able test yet. prefer database way far abilities.
once again thank help.
Comments
Post a Comment