Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3321994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:07:47+00:00 2026-05-17T23:07:47+00:00

I set it up so that every time you view a product a value

  • 0

I set it up so that every time you view a product a value is updated in a database table daily_product_stats. It should only count your view once per session per product. So to see how many times product 435 was viewed today we can easily do that, and easily see which product is getting looked at the most today.

But I started noticing strange results, like product 2324 was looked at the most at 36 times by 9am. I was suspicions something was not right since thats not a very popular product.

So I decided to also track each individual view with an ip to make sure each view was unique. So everytime I update daily_product_stats I am inserting a new row into product_ip_tracking with the IP.

So I did this for a few minutes and the results got stranger.

First, here is the code on the page that is doing the tracking:

include_once("php/packages/pdomanager/PDOManager.php");

$pdo = PDOManager::getConnection();


$product_stat_qry = '
    INSERT INTO daily_product_stats
    SET product_stat = 1, product_id = :pid, first_entry = :date
    ON DUPLICATE KEY UPDATE product_stat = product_stat+1
';

// Update temp stat table
$product_ip_tracking_qry = '
    INSERT INTO product_ip_tracking
    SET product_id = :pid, date = :date, user_ip = :ip
';

$stat_data = array(
    "pid" => $_GET['pid'],
    "date" => date('Ymd')
);

$track_data = $stat_data;
$track_data["ip"] = $_SERVER['REMOTE_ADDR'];

$stat_sth = $pdo->prepare($product_stat_qry);
$track_sth = $pdo->prepare($product_ip_tracking_qry);

if(!isset($_SESSION['daily_product_stats'][$_GET['pid']]))
{ // only update once per person per session
    $stat_sth->execute($stat_data);
    $track_sth->execute($track_data);
    $_SESSION['daily_product_stats'][$_GET['pid']] = 1;
}

Looking at the 2 different queries that get executed together, you should be able to assume that whatever product_stat is for a product_id on the daily_product_stats table there should be that many rows for the same product_id on the product_ip_tracking table.

So I let it run for a few minutes and then I ran this query on the database:

SELECT product_id, COUNT( user_ip ) AS times, user_ip, DATE
FROM  `product_ip_tracking` 
GROUP BY user_ip
ORDER BY times DESC , product_id

and I found that product_id 8151 was viewed 84 times today from the same IP address 66.249.65.123. I thought my code should prevent the same IP from being tracked more than once per day. I did some research on the IP and it looks like it most likely a Google bot, so I thought maybe SESSIONS can’t be set with bots, so thats why its getting tracked multiple times…

So I then expected to look into the daily_product_stats table for product_id 8151 and for its product_stat to be 84. It was not, it was only 2. I find this very bizarre because I do not see how that is possible. I am not sure at all what is going on here.

Does anyone have any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:07:47+00:00Added an answer on May 17, 2026 at 11:07 pm

    your select query looks a little funky, so that probably explains your funky result. Intuitively you’re not just grouping on IP but also on Product and Date, so you should add product_id and date to your GROUP BY clause. Thus, your query should be more like this:

    SELECT product_id, COUNT(user_ip) as times, user_ip, date
    FROM `product_ip_tracking`
    GROUP BY product_id, user_ip, date
    ORDER BY times DESC, product_id
    

    I’ll defer to someone who is more knowledgeable with the PDO MySQL library to help you out with your app logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view with a huge paginated list of records that need filtering.
I am trying to set an ImageView's background every x seconds. The used Drawables
Basically the back story is that i've built a selecting of python scripts for
I was wondering what is the correct way to set the text of a
I have made an openGL camera class that uses lazy evaluation to provide the
I have made an openGL camera class that uses lazy evaluation to provide the
Update: There is no problem here. Turns out I was re-adding the animation every
I am writing a SplitView iPad app. Inside the DetailViewController, there's a little view
I'm using the Codeigniter framework and have tried to stick with the MVC philosophy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.