Web Analytics Made Easy -
StatCounter Help me spot the bug? - CodingForum

Announcement

Collapse
No announcement yet.

Help me spot the bug?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Help me spot the bug?

    Have a small bug and can't find it. There are 4 character classes, and the WHILE loop works fine as you can see the items are different.

    But it's displaying Enchantress as the class for all items. The Small Cane should be Enchantress, Fayts Sword should be Knight, and The knife should be Thief.

    The database is correct, I triple checked it. But it's something all in the same class.

    Then in the equip function, it gives me the error that I am not the same character class. Any help?

    INVENTORY
    PHP Code:
      $weaponquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND type='1'"'smithcreate');
        
    $classweapon mysql_fetch_array($weaponquery);
        

            
    $title 'Equipment Inventory';
            
    $page "<table width='100%' border='1'><tr><td class='title'><a href='index.php'>Gameplay</a> > <a href='equipinv.php'>Equipment Inventory</a></td></tr></table>";

            
    $page .= "<table width='100%'><tr><td class='title'><center><h3><font color=white>WEAPONS</font></h3></center></td></tr></table>";
            
    $page .= '<p><table width="95%">';
            
    $page .= '<tr><td><b>Weapon Name</b></td><td><b>Min Level</b></td><td><b>Damage</b></td><td><b>Class</b></td><td><b>Upgrade</b></td><td><b>Action</b></td></tr>';
            if (
    mysql_num_rows($weaponquery) == 0) {
              
    $page .= '</table>';
              
    $page .= '<center><p>You have no weapons in your inventory.</center>';
            }
            else {
            while (
    $wrow mysql_fetch_array($weaponquery)) {

             if (
    $classweapon['class'] == 1) {
          
    $weapon1 'Enchantress';
        }
        elseif (
    $classweapon['class'] == 2) {
          
    $weapon1 'Knight';
        }
        elseif (
    $classweapon['class'] == 4) {
          
    $weapon1 'Archer';
        }
        elseif (
    $classweapon['class'] == 7) {
          
    $weapon1 'Thief';
        }

            if (
    $wrow['equipped'] == 'No') {
              
    $setweapon "<a href='equipinv.php?x=equipweapon:".$wrow['id']."'>EQUIP</a>";
            }
            else {
              
    $setweapon "<a href='equipinv.php?x=unequipweapon:".$wrow['id']."'>REMOVE</a>";
            }

            
    $page .= "<tr><td>".$wrow['name']."</td><td>Lvl ".$wrow['requirement']."</td><td>+".$wrow['attribute']."</td><td>$weapon1</td><td>+".$wrow['bonusattack']."</td><td>$setweapon</td></tr>";
          }
          
    $page .= '</table>'

    EQUIP
    PHP Code:
    function equipweapon($id) {

        global 
    $userrow$numqueries;

        
    $updatequery doquery("UPDATE {{table}} SET location='Equipment Inventory' WHERE id='".$userrow["id"]."' LIMIT 1""users");

        
    $weaponquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND id='$id'"'smithcreate');
        
    $equipw mysql_fetch_array($weaponquery);

        if (
    $equipw['class'] == 1) {
          
    $equipw2 'Enchantress';
        }
        elseif (
    $equipw['class'] == 2) {
          
    $equipw2 'Knight';
        }
        elseif (
    $equipw['class'] == 4) {
          
    $equipw2 'Archer';
        }
        elseif (
    $equipw['class'] == 7) {
          
    $equipw2 'Thief';
        }

        if (
    $equipw2 != $userrow['charclass']) {
          
    display("<p>Your not the same class as this weapon requires.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }
        
        if (
    $userrow['level'] < $equipw['requirement']) {
          
    display("<p>You aren't a high enough level to equip this weapon.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }
        
        if ((
    $userrow['weaponid'] != 0) || $userrow['weaponname'] != 'None') {
          
    display("<p>You already have a weapon equipped. Please remove it first.<br /><br /><a href=\"equipinv.php\">Equipment Inventory</a>.""Error");
        }

            
    $title 'Equipment Inventory';
            
    $page "<table width='100%' border='1'><tr><td class='title'><a href='index.php'>Gameplay</a> > <a href='equipinv.php'>Equipment Inventory</a> > Equip Weapon</td></tr></table>";

           
        
    $page .= "You have successfully equipped the <b>".$equipw['name']."</b>."
    Last edited by myfayt; Aug 26, 2011, 03:23 PM.
    Been a sign maker for 8 years. My business:
    American Made Signs

  • #2
    Start by dumping the values you are comparing to reach that logic and work backward from there to see how they got those values.

    Comment


    • #3
      Ah ha! tricky little bug. in the IF and ELSEIFs had to change $classweapon to $wrow
      Last edited by myfayt; Aug 26, 2011, 03:22 PM.
      Been a sign maker for 8 years. My business:
      American Made Signs

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎