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 8226965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:57:30+00:00 2026-06-07T15:57:30+00:00

I am creating a jsp page where a single news item is shown, just

  • 0

I am creating a jsp page where a single news item is shown, just like the single question on this StackOverflow page. I need to store the view count in a database.

I can simply increment the view count in the database this way:

`UPDATE table SET views=views+1 WHERE newsId=4458;`

But what if a single user hits that page again and again and again, say 50 times… In this case, my view count will not represent unique visitors to the site. How can I avoid this?

I want something like StackOverflow’s view count system.

  • 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-07T15:57:33+00:00Added an answer on June 7, 2026 at 3:57 pm

    well one solution could be you make a new table (lets say its called views) with the following columns ‘viewid’ ‘newsid’ ‘ipaddress’ (obviously newsid is the foreign key)
    every time someone visits ur website u check if his ip is already in that table for that news item.

    Select count(*) AS count FROM views WHERE newsid=1234 AND ipaddress=123.456.125
    

    if count equals 0 you insert like this

    INSERT INTO views('newsid', 'ipaddress') VALUES(1234, 123.146.125)
    

    Now when you want to fetch the viewcount:

    Select count(*) AS count FROM views WHERE newsid=1234
    

    you can enhance this by adding another column called ‘count’ and ‘lastviewed’ (type datetime) to the table views.
    Lets say you allow every ip to be counted another time if the day doesnt match.
    This way you will get a pretty accurate viewcount 🙂

    to fetch the new viewcount you can simply use SUM

    Select SUM(count) AS count WHERE newsid=1234
    

    Good luck 🙂

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

Sidebar

Related Questions

I am creating a JSP page, I get data from database this data is
I am creating a project in struts2 I have created a Registration.jsp page like
I am having a JSP page, where i am dynamically creating a Table data.
I am having a problem with a .jsp page I am creating. For those
I'm creating a survey-like page. I use three basic JavaScript functions, goNext(i) which hides
I am creating .jsp page and reiceve error about it ; String energyv=; int
I am creating a page in JSP where I have a dropdown list and
I have a button on my .jsp page that I would like to act
I am creating a jsp page to test a validator servlet for a uni
I am creating one jsp page in which I read in a text file,

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.