Jump to content

Need help with a script


bazrim11
Go to solution Solved by requinix,

Recommended Posts

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;
    
}
 
 
 
 
 
 
 
 
 
?>
 
Link to comment
Share on other sites

  • Solution

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'];
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.