Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question PHP - Page Counter

    Hi

    I am trying to create a page counter in PHP.

    Table structure:
    Code:
    Table Name: tbl_counter
    Column Name:total_views
    Column Datatype: integer
    I am using the following SQL query on the page.

    Code:
    UPDATE tbl_counter SET total_views=total_views+1
    I know its weird but, sometimes the counter increases twice instead of 1, any idea why?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The SQL is correct, so the only way that can happen if there is multiple loads of the page. This could be caused by inclusions depending on you're page setups of course. Chances are though, it was just another visitor or a spider crawling the net.
    If you're on you're local system, I'd check you're log files. Apache really shouldn't accept connections from the outside world in you're testing environment. I left mine open once. It was bad.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    I am using this locally, and no one has incoming access to my system.

    I know its weird, but I could not find a fool-proof solution to this.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Its definitely from multiple executions of the file though. Either its an external influence, or its being included multiple times into another file. There is not enough information to determine if its a problem being created through the program code.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    whats the solution then?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    There isn't really a solution. Debugging you're code is the best I can offer, if you have a decent IDE with a debugger (I use the zend eclipse IDE, its not great, but I've used much worse), you can step through each step of you're code to see how many times its executing. I'll warn you though, you can't use external libraries when you're debugging, so you'll need to comment out you're mysql connections and queries. But at least you'll see it as you step over it which can help to identify what the problem is and how you can solve it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    @cancer10, have a try by emptying your table and making a fresh "Page view"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •