Re: A tricky and interesting mysql-php problem................
| From: | James | Date: | Sat, 17 May 2003 20:57:55 +0000 |
| Subject: | Re: A tricky and interesting mysql-php problem................ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148044@lists.php.net to get a copy of this message | ||
You have to take some time to explain this again, trying to as clear as
possible. State what the project is about, what you are trying to achieve
and what is going wrong.
Your code is most likely to blame and from the example it's not really a
suprise.
Jim.
"System" <system@eluminoustechnologies.com> wrote in message
news:03d401c31c9a$368ac030$1a01a8c0@vishal...
> A tricky and interesting mysql-php problem................
>
> I am executing a script in php.
> This executes a 3 mysql queries
> e.g.
>
> $query11="select * from ".$prefix."account where
> username='$Cusername'
and
> current=1";
> $result11=mysql_query($query11);
> $total11=mysql_num_rows($result11);
> if($total11)
> {
> $row11=mysql_fetch_object($result11);
> $bal=$row11->balance;
> }
> else
> $bal=0;
>
> $queryc="update ".$prefix."account set currentrec=0 where
> username='$user'";
> $resultc=mysql_query($queryc);
>
> $queryacc="insert into
>
".$prefix."account(username,deposited,balance)values('$user','$pay','$newbal
> ')";
> $resultacc=mysql_query($queryacc);
>
> This updates account of a user
> If user purchase 10 items at a time then this 3 mysql queries executes 10
> times in a loop as per the requirement.
>
> Now when there are 10-20 such users online at a time and if they purchase
> 10-10 items
> this mysql queries executes 100-200 times. Untill here its ok.
> But here after the problem starts. Mysql should not allow the second user
> for loop to execute until the first user for loop is completed. It
randomly
> takes the user and starts executing the mysql query in for loop before
> satisfying the first user.
>
> for($i=1,$i<=10;$i++)
> {
> $query11="select * from ".$prefix."account where username='$user'
> and
> current=1";
> $result11=mysql_query($query11);
> $total11=mysql_num_rows($result11);
> if($total11)
> {
> $row11=mysql_fetch_object($result11);
> $bal=$row11->balance;
> }
> else
> $bal=0;
>
> $queryc="update ".$prefix."account set currentrec=0 where
> username='$user'";
> $resultc=mysql_query($queryc);
>
> $queryacc="insert into
>
".$prefix."account(username,deposited,balance)values('$user','$pay','$newbal
> ')";
> $resultacc=mysql_query($queryacc);
> }
>
> It executes $query11 for first user and then again $query11 for second
user
> then
> $queryc for first user and so on ............
> anything randomly happens here.
> We just cant predict what will happen.
> This leads to all wrong accounts .And its a big problem.
> I want that it should first complete request for first user and then for
> second and so on.....
> If first users request is not completed it should hold second user for
that
> time and so on...
> Is anybody having same problem or any solution?
>
> Thank you,
>
> Tina...
>
>
>