mySQL updating information prev.pageview

admin

Administrator
Staff member
On the index page of a new website I'm currently creating, I have a box named 'In the picture' where a pseudo-random entry from a table of companies (mySQL database) is selected and printed.
The selection is based on the number of views this company had and, if this number is the same for more than 1 company, next randomly. After printing the results, the number of views is updated.

The problem now is, that when I refresh this page both the number of views of the previous pageview with my browser and the number of views of this pageview's company is increased by 1 (and of course only the current pageview's company should have it's ITPView field increased)!

Can someone explain me how this is possible and how to circumvent this problem?

The code is listed below.
________________

// Select a random row from table Companies
$CompanySQL = "SELECT * FROM Companies ORDER BY ITPViews, RAND() LIMIT 1";
$CompanyResult = mysql_query($CompanySQL);
$company = mysql_fetch_array($CompanyResult);

// printing some data from company[] array

// Update the views of this company
$newViews = $company[ITPViews] + 1;
$UpdateSQL = "UPDATE Companies SET ITPViews = $newViews WHERE CompanyID = $company[CompanyID]";
$UpdateResult = mysql_query($UpdateSQL);
_________________
 
Back
Top