uwannadonkey Posted August 13, 2007 Share Posted August 13, 2007 if ( $user->agility > $enemy->agility) { $firstattack = '1'; } else { $firstattack = '2'; } while ($user->hp > 0 && $enemy->hp > 0) { if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } } thats my code, its my first time using the while() function, and im not very clear with it. no errors show up, and nothing happens, i mean, the page stays blank. can anyone help me? is it the &&? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/ Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 never ending loop, you need to update the values for $user->hp $enemy->hp Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322299 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 how would i do that? i thought it did that by itself. thx for the reply by the way Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322301 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 if it was a never ending loop, wouldnt it never load the page? the page loads, but nothing happens :/ Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322311 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 OK add this if ( $user->agility > $enemy->agility) { $firstattack = '1'; } else { $firstattack = '2'; } while ($user->hp > 0 && $enemy->hp > 0) { die("IN the WHILE LOOP ");//ADD THIS echo "attack<br>"; //add flush(); //add if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } } if you dont get a message "IN the WHILE LOOP " then your values are lower than 0, comment that line out and see what happens Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322314 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i added it, and nothing was written, well nothing that wasnt there before. PS what do u write to put the php in that box, just like you just did. Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322317 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 use the # button (on the toolbar) AKA [quote author=MadTechie link=topic=154575.msg669149#msg669149 date=1187009615] if you dont get a message "IN the WHILE LOOP " then your values are lower than 0, comment that line out and see what happens [/quote] add to the start [code] echo "User HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; your see the theirs no value are you including the class ? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322320 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 you are right, there is no value for enemy hp, but i set it... <?php include('inc/header.php'); if (isset($_GET[iD])); { $result2 = @mysql_query("SELECT * FROM users WHERE ID = '$_GET[iD]'"); $temp3 = @mysql_fetch_object($result2); $enemy = $temp3; echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) {echo ' You are in NO condition to do battle'; } elseif ($enemy->hp = 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength. You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$_GET[iD]'"); } else { echo' Welcome to the Battle Arena.'; if ( $user->agility > $enemy->agility) { $firstattack = '1'; } else { $firstattack = '2'; } echo "User HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; while ($user->hp > 0 && $enemy->hp > 0) { echo "attack<br>"; //add flush(); //add if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } } } include('inc/footer.php'); ?> Thats the full code on the page on the page, it show: GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 which means that enemy->display_name is working, because the enemies name is there, right? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322323 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 change the $enemy->ID to $enemy['ID'] $enemy->hp to $enemy['hp'] etc etc etc etc try a few and check it works then continue EDIT AHHH wait a sec.. echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; worked ! *thinking* try print_r($enemy), and post the result from that Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322325 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 ok, ill change em all and get back to you GOD VS. GOD Welcome to the Battle Arena.User HP:190 Enemy HP: Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322330 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 can you echo "enemy"; print_r($enemy); echo "user"; print_r($user); and post the result from that i think their around the wrong way! Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322340 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i wrote what u told me to, and this came up: enemystdClass Object ( [iD] => 9 [username] => CatNCobra [display_name] => CatNCobra [password] => ecb69279ec2c85c2a63ad2f43b8bbeb5 => [email protected] [activation_code] => 6a1dc38c5621a76daf3e3acf76b1baa0 [permission_level] => 0 [donator_days] => 0 [level] => 51 [exp] => 0 [exp_required] => 75 [energy] => 7 [max_energy] => 150 [hp] => 0 [max_hp] => 100 [attack] => 1895 [defense] => 5 [agility] => 5 [diamond] => 5 [gold] => 0 [avatar] => [sig] => [energy_used] => 0 [iP] => [battle_won] => 0 [battle_lost] => 0 [total_battles] => 0 [storage] => 0 [bank_gold] => 4417 [crystal] => 8 [element] => 0 [rank] => 0 [forest] => 0 [gold2] => [weapon] => 0 ) userstdClass Object ( [iD] => 1 [username] => uwannadonkey [display_name] => GOD [password] => aa46d20cfecbc87d62db3597410efc96 => [email protected] [activation_code] => abf05a23cdb753cb083b0d4443dfd593 [permission_level] => 127 [donator_days] => 500 [level] => 100 [exp] => 0 [exp_required] => 75 [energy] => 5 [max_energy] => 150 [hp] => 190 [max_hp] => 687 [attack] => 273 [defense] => 5 [agility] => 5 [diamond] => 5 [gold] => 1391 [avatar] => [sig] => [energy_used] => 0 [iP] => [battle_won] => 0 [battle_lost] => 0 [total_battles] => 0 [storage] => 0 [bank_gold] => 688 [crystal] => 11 [element] => 0 [rank] => 0 [forest] => 2323185 [gold2] => [weapon] => 0 ) Welcome to the Battle Arena.User HP:190 Enemy HP:0 any help? Y is his HP=0? in my mysql, it says he has 100 hp Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322343 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 it says his HP is 0, but when i look in mysql database, it says its 100... Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322345 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 ok try this <?php include('inc/header.php'); $eID = $enemy->ID; $uID = (int)$_GET['ID']; if ($uID > 0) //changed { $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) { echo ' You are in NO condition to do battle'; } elseif ($enemy->hp = 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength. You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$_GET[iD]'"); } else { echo' Welcome to the Battle Arena.'; if ( $user->agility > $enemy->agility) { $firstattack = '1'; }else{ $firstattack = '2'; } echo "User HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; while ($user->hp > 0 && $enemy->hp > 0) { $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "attack<br>"; //add flush(); //add if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $_GET[iD]"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } } } include('inc/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322349 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 off the bat, it says : Parse error: syntax error, unexpected T_IF in /home/donkey9/public_html/attack.php on line 8 wait, is that the semi colon u put after the if statement? EDIT *not the semi colon Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322350 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 lol opps updated it Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322351 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 CatNCobra VS. CatNCobra You cant attack yourself!This page took 0.000095 seconds to load. why is he attacking himself now? $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); thats the problem *edit* user is set in the header include on the top of the code why set it again, and the same value as enemy? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322352 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 i made a few updates, try now Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322354 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 more problems: u didnt set eID at all and this is what shows up: CatNCobra VS. Your opponent takes one look at you, and dies in fear *Edit* like i said previously, USER is set in the header file, so should i remove that part of codE? noticed ur error, the get[id] gets the enemie's ID from the url and the user is always included in the file header i modified ur code into this: $uID = $user->ID; $eID = (int)$_GET['ID']; if ($uID > 0) //changed { $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); and this shows up GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322357 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 remember i can't test this,.. ok i have reviewd everything (i think) Wait noticed a ton some fo the logic is a little weird! would you mind if i update a few thing ? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322359 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 i wrote stuff on my previous post, after changing ur code a bit, i think its starting to work, up until the while() code lol, sure, anything that can help! (PS thanks for helping me so much already, and thanks for sticking with this.) i ono why the enemy HP is showing as 0, ID 9 in mysql is 100 hp Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322362 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 is the $_GET['ID'] the ID from the attacker ? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322365 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 $get[id] is the ID of the enemy ie: the user attacks the enemy, and the enemies ID is in the url does that help ? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322366 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 OK <?php include('inc/header.php'); $eID = (int)$_GET['ID']; $uID = $user->ID; if ($uID > 0) { #commented out if called from header! #$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); #$user = @mysql_fetch_object($usersql); $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) { echo ' You are in NO condition to do battle'; } elseif ($enemy->hp = 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength. You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$enemy->ID'"); } else { echo' Welcome to the Battle Arena.'; if ( $user->agility > $enemy->agility) { $firstattack = '1'; }else{ $firstattack = '2'; } echo "User HP:".$user->hp; echo "<br>Enemy HP:".$enemy->hp; while ($user->hp > 0 && $enemy->hp > 0) { echo "attack<br>"; //add flush(); //add if ($firstattack == 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack == 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } if ($firstattack != 1) { $dmg = ($user->attack) - ($enemy->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID"); echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name"; } if ($firstattack != 2) { $dmg = ($enemy->attack) - ($user->defense); mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID"); echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name"; } //get new values $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $user = @mysql_fetch_object($usersql); } } include('inc/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322373 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 GOD VS. CatNCobra Welcome to the Battle Arena.User HP:190 Enemy HP:0 is what shows on the page, but his HP isnt 0 why is that happening? Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/#findComment-322374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.