Not sure how to describe this problem..
| From: | Chad Day | Date: | Tue, 10 Jul 2001 13:16:52 +0000 |
| Subject: | Not sure how to describe this problem.. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-57146@lists.php.net to get a copy of this message | ||
I have a chunk of code in a webpage that works like this, to rotate some
ads.. :
if ($row = mysql_fetch_array($getads)) {
do {
$POS = $row[LASTPOS];
$ID = $row[ID];
$POS++;
if ($POS > $numads) {
$POS = 1;
}
$update = mysql_query("UPDATE adtracker set LASTPOS = '$POS' where ID =
'$ID'");
echo $row[LINKLOC];
} while ($row = mysql_fetch_array($getads));
}
so it grabs the last position that ad was in from the DB, increments it by
1, unless incrementing it would push it past the max # of ads, so it resets
the position to 1.
The problem is, the site gets a lot of traffic, and instead of the ads
retaining positions like:
1, 2, 3 or 2, 3, 1 or 3, 1, 2 as they should, I've seen it somehow
go to:
1, 1, 3, or 2, 2, 1 etc.
So I guess what is happening is that when 2 people hit the page at the exact
same time, it's getting updated values out of the DB for some of the ads
before they are all updated.. how can I go about controlling this?
Thanks,
Chad