bazrim11 Posted January 17, 2014 Share Posted January 17, 2014 Im making a game while trying to learn php and as a way to augment weapons and armour im adding gems to the game rubys diamonds emeralds and crystals and im making super gems (more poewerful) and master gems (most powerful) and using this script im converting regular gems to super gems i got rubys to do it fairly easy but when i started trying to do the diamonds it just tell me i dont have neough gems though i have 1 million in my database. I need help figuring out why this isnt working i tried using if statements and a switch and this is my current code for the converter its pretty simeple but im just missing something. <? $sruby='super ruby'; $gem=$_POST['start']; $type=$_POST['finish']; $result=mysql_query("SELECT * FROM items WHERE username='".$_SESSION['username']."'"); while($row = mysql_fetch_array($result)) $ruby=$row['ruby']; $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal']; switch (true) { case $gem==ruby: if($type=='super' && $ruby>='500'){ mysql_query("UPDATE items SET ruby=ruby-500 WHERE username='".$_SESSION['username']."'"); mysql_query("UPDATE items SET sruby=sruby+1 WHERE username='".$_SESSION['username']."'"); echo('You have just converted your 500 rubies to 1 super ruby'); } else{ echo('You do not have enough rubies'); } break; case $gem==diamond: if($type=='super' && $diamond>='500'){ mysql_query("UPDATE items SET sdiamond=sdiamond+1"); Echo("YOu converted 500 diamonds to 1 super diamond"); } else{echo("You do not have enough diamonds");} break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285432-need-help-with-a-script/ Share on other sites More sharing options...
Solution requinix Posted January 17, 2014 Solution Share Posted January 17, 2014 while($row = mysql_fetch_array($result)) $ruby=$row['ruby']; $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal'];If you don't use {}s on a loop then only the next statement will be executed in the loop. Like while($row = mysql_fetch_array($result)) { $ruby=$row['ruby']; } $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal'];After the loop $row will be false (it read everything) and you won't have any diamonds, emeralds, or crystals. In your case, forget the loop. There's only one row. $row = mysql_fetch_array($result); $ruby=$row['ruby']; $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal']; Quote Link to comment https://forums.phpfreaks.com/topic/285432-need-help-with-a-script/#findComment-1465518 Share on other sites More sharing options...
bazrim11 Posted January 17, 2014 Author Share Posted January 17, 2014 Thank you that has been driving me crazy and it fixed it Quote Link to comment https://forums.phpfreaks.com/topic/285432-need-help-with-a-script/#findComment-1465520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.