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

  • SEARCH
  • Home
  • 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 9187213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:42:49+00:00 2026-06-17T19:42:49+00:00

I have a reports table where i count hits by just using the code

  • 0

I have a reports table where i count hits by just using the code below.

// Get hits
    $hits_query = mysql_query("SELECT COUNT(*) AS `count` FROM `reports` WHERE `stuff_id` = ".$row->id."");
    $fetch_hits = mysql_fetch_array($hits_query);
    $hits = $fetch_hits['count']; 

That code works great and does exactly what i want but what i want now is how to get unique hits?

In my reports table i store every access so theres multiple log for each user base on the stuff_id . In my reports table I store the date as 01-23-2013 on each report, along with the user ip and stuffed which every 24 hours change from 2 to 1.

  • 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-06-17T19:42:50+00:00Added an answer on June 17, 2026 at 7:42 pm

    You need a field that uniquely identifies the user. I am going to assume for my example that it is user_ip. Change this:

    $hits_query = mysql_query("SELECT COUNT(*) AS `count` FROM `reports` WHERE `stuff_id` = ".$row->id."");
    

    To this:

    $hits_query = mysql_query("SELECT COUNT(DISTINCT `user_ip`) AS `count` FROM `reports` WHERE `stuff_id` = ".$row->id."");
    

    NOTE: mysql library will be deprecated as of PHP 5.5 and removed in future versions of PHP. It would be a good idea to start planning a migration away from it.

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

Sidebar

Related Questions

I have 2 tables, using an inner join to query them. SELECT COUNT(table2.id) FROM
I have a table I am trying to generate reports from. Its basically a
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I have a table as shown below The output from said table Green, is
I have a table containing reports and the date/time they were created. I'd like
I have an entity defined as follows @Entity(name = Report) @Table(name = REPORTS) @org.hibernate.annotations.Entity(dynamicInsert
The Situation (Ignore this it is boring): I have reports that I created using
I'm using MySQL and I have the following table: | clicks | int |
I have a table of reports that has these relevant fields: user_id (int 11)
I have a report that pulls information from a summary table and ideally will

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.