Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-08-10, 02:38 AM
Junior Member
 
Join Date: Dec 2007
Posts: 12
cancer10 is on a distinguished road
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?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2008-08-25, 03:17 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

try tossing a limit 1 onto the end of the sql statement.

I agree it is very odd, but that may clear it up.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2008-08-26, 11:45 AM
Junior Member
 
Join Date: Aug 2008
Posts: 2
vbplusme is on a distinguished road
Send a message via Yahoo to vbplusme Send a message via Skype™ to vbplusme
Default

I am guessing a page refresh.

I tested this query with over 100K loops and it never double stamped so I am thinking that you may have done a page refresh to get the extra count? Just a guess.

Here is my query:

PHP Code:

$query 
"UPDATE `tbl_counter` SET `total_views`= `total_views`+ 1 ";
mysql_query($query) or die('Error, query failed'); 
I stuck it in a for loop to see if it would add any extra updates and it did not.

HTH,

vbplusme
Reply With Quote
  #4 (permalink)  
Old 2008-08-26, 01:10 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

That is an excellent thought!! The query does look fine to me as well.

What are you doing in the webpage after you run the query? Going to the same place or are you redirecting to keep the refresh problems from happening?
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:21 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.