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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:41:42+00:00 2026-06-11T02:41:42+00:00

I own a image hosting website and I capture image views using php and

  • 0

I own a image hosting website and I capture image views using php and mysql.

I use the following code to count the views.

include 'mysql.php';

$result = mysql_query("SELECT * FROM DB WHERE ID='$id'");
$row = mysql_fetch_array($result);
$views=$row['views'];

$query = "UPDATE DB SET views=$views+1 WHERE ID='$id'";
$result2 = mysql_query($query);

mysql_close($con);

views is mediumint(9) type field.

I noticed that the views get decreased day by day.can anyone say what is the problem and offer a solution.

Thanks.

  • 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-11T02:41:43+00:00Added an answer on June 11, 2026 at 2:41 am

    You should use this to update instead:

    $query = "UPDATE DB SET views=views+1 WHERE ID='$id'";
    

    If a page takes a long time to execute, you can have one query overwrite another. Also using this, you might not need to even run the first query – unless you want other info from it.

    The reason you are getting an error is that one script is reading the data and grabbing the value, then updating it – based on the value it is storing – but in the meantime other scripts could be updating the row. You could avoid it by using transactions, but that seems utter overkill for what you are doing.

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

Sidebar

Related Questions

I use ViewPager to implement my own image gallery. The views consists of ImageView
I want to use my own image of arrow for items in listview. Where
I've seen a lot of people try to code their own image conversion techniques.
I used that article on code project to create my own Captcha image, is
i am wondering if its ok to request users to use own hosting resources
I'd like to use my own image as handler's image. How can i change
I am using nicEdit editor and I have added my own custom image resizing
i want to change navigation bar background using my own image, but i really
I am using SetCursor to set the system cursor to my own image. The
I am developing an MFC application. I am working with my own .bmp image

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.