not relooping

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rufee
Forum Newbie
Posts: 10
Joined: Wed Dec 09, 2009 10:23 am

not relooping

Post by rufee »

Hello
I have this script going

Code: Select all

$query = "SELECT `building_id`, `amount`, `ticks` FROM `game_resource_build` WHERE `user_id` = '$user_id'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$building_id = $row['building_id'];
$amount = $row['amount'];
$ticks = $row['ticks'];
 
echo "Bid: $building_id";
echo "\n";
echo "Amount: $amount";
echo "\n";
echo "Ticks: $ticks";
echo "\n";
 
if($ticks > 0){
$query = "UPDATE `game_resource_build` SET `ticks`= `ticks`-1 WHERE `building_id` = '$building_id' AND `user_id` = '$user_id' AND `ticks` > 0";
mysql_query($query);
 
 
$query = "SELECT `ticks` FROM `game_resource_build` WHERE `building_id` = '$building_id' AND `user_id` = '$user_id' AND `ticks` = 0 LIMIT 1";
$result = mysql_query($query);
$newticks = mysql_num_rows($result);
 
if($newticks == 1){
$query = "INSERT INTO `game_resource_buildings` (`user_id`, `building_id`, `amount`) VALUES ('$user_id', '$building_id', '$amount')";
mysql_query($query);
$query = "DELETE FROM `game_resource_build` WHERE `building_id` = '$building_id' AND `user_id` = '$user_id' AND `ticks` = 0";
mysql_query($query);}}
 
}
everything like $user_id is declared

so the problem is its not relooping
i have more then one entries in the database it only performs actions on one at file execution(like a queue) which is not what i want
Where did i go wrong?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: not relooping

Post by jayshields »

You're overwriting a variable used in the while condition inside your loop.
rufee
Forum Newbie
Posts: 10
Joined: Wed Dec 09, 2009 10:23 am

Re: not relooping

Post by rufee »

jayshields wrote:You're overwriting a variable used in the while condition inside your loop.
Which exactly ?
EDIT: oh found it it was $result
Post Reply