如果ElseIf Else在随机事件代码中出错

时间:2013-08-27 20:06:51

标签: php

这是我的完整代码,当我把所有其他的东西当作其他所有东西时,这完全没问题。

但我需要第一个if语句才能运行。这样,如果他们的最小转弯次数少于最小值,他们就不会大声继续。 这是我得到的错误...... 解析错误:语法错误,意外T_ELSEIF

CODE

<?php

$ingame = "*";
require 'includes/header.php';
include 'includes/modzoideditables.php';
include 'includes/zoideditables.php';
include 'includes/offdefvalues.php';
$turns = 5;
$turns2 = 10;
$zoidmany = 1;
$zoidmany2 = 2;
$excav1 = 1;
$excav2 = 0;
$goldgive1 = 500;
$goldgive2 = 700;
$goldgive3 = 1000;
$goldgive4 = 1500;
$goldgive5 = 2000;
$fight1 = 20000;
$fight2 = 27000;
$fight3 = 31000;
$goldtake1 = 250;
$goldtake2 = 500;
$goldtake3 = 750;
$goldtake4 = 1000;
$miner = 5;

    $rand = rand( 1, 22 );
if ( $turns > $user['uAttackTurns'] ) {
        echo "You don't have enough turns.";
}   
    $rand = rand( 1, 22 );
 elseif ( $excav1 > $user['uExcavation2'] ) {
}   
   else ( $rand == 1 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php
    }
    else ( $rand == 2 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany2,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php

        }
        elseif ( $excav2 = $user['uExcavation2'] ) {
}   
   else ( $rand == 1 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
     ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php
    }
    else ( $rand == 2 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php

    }
            elseif ( $rand == 3 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uWeapon42=uWeapon42+$zoidmany,uAttackTurns=uAttackTurns+'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>You see something shiny in the distance, What is that you wonder?</b></center><br /><?php
        ?><center><b>You just found a fully working <?=$wp_42_nm?>!<img src="<?=$wp_42_image?>"/></b></center><br /><?php
        ?><center><b>No need for excavation tools here, This bad boy runs!</b></center><br /><?php
    }
         elseif ( $fight2 > $defensetotal ) {
}   
   else ( $rand == 4 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive3?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php
    }
    elseif ( $fight2 < $defensetotal ) {
}   
   else ( $rand == 4 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake2?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php
    }
             elseif ( $fight1 > $defensetotal ) {
}   
   else ( $rand == 5 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive2?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php
    }
    elseif ( $fight1 < $defensetotal ) {
}   
   else ( $rand == 5 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake1?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php
    }
    elseif ( $rand == 6 || $rand == 7 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$gold1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just got ambushed. You loose 50 gold!</b></center><br /><?php
    }
            elseif ( $rand == 8 || $rand == 9 || $rand == 10 || $rand == 11  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>After a long hard journey you come up empty handed!</b></center><br /><?php
    }
    elseif ( $excav1 > $user['uExcavation2'] ) {
}   
   else ( $rand == 12 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uEleshotbrhinosweap=uEleshotbrhinosweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/>You decide to keep it!</b></center><br /><?php
    }
    elseif ( $excav2 = $user['uExcavation2'] ) {
}   
   else ( $rand == 12 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
     ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php
    }
         elseif ( $fight3 > $defensetotal ) {
}   
   else ( $rand == 13 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive4,uWeapon48=uWeapon48+$zoidmany,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive4?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>You also managed to take a fully working <?=$wp_48_nm?>, <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php
    }
    elseif ( $fight3 < $defensetotal ) {
}   
   else ( $rand == 13 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake3?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php
    }
        elseif ( $rand == 14 || $rand == 15 || $rand == 16 || $rand == 17  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$goldgive1?> Gold. You decide to keep it!</b></center><br /><?php
    }
        elseif ( $rand == 18 || $rand == 19 || $rand == 20 || $rand == 21  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uMiners=uMiners+$miner,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just found <?=$miner?> miners, your forcing them to join you!</b></center><br /><?php
    }
elseif ( $turns > $user['uAttackTurns'] ) {
}   
   else ( $rand == 22 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-$turns,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just lost an additional <?=$turns?>. Better luck next time!</b></center><br /><?php
    }

require 'includes/footer.php';

?>

以下是工作代码,这是我遇到的唯一问题,当他们获得转机限制时,他们仍然会因此而导致他们陷入负面转折。

    <?php

$ingame = "*";
require 'includes/header.php';
include 'includes/modzoideditables.php';
include 'includes/zoideditables.php';
include 'includes/offdefvalues.php';
$turns = 5;
$turns2 = 10;
$zoidmany = 1;
$zoidmany2 = 2;
$excav1 = 1;
$excav2 = 0;
$goldgive1 = 500;
$goldgive2 = 700;
$goldgive3 = 1000;
$goldgive4 = 1500;
$goldgive5 = 2000;
$fight1 = 20000;
$fight2 = 27000;
$fight3 = 31000;
$goldtake1 = 250;
$goldtake2 = 500;
$goldtake3 = 750;
$goldtake4 = 1000;
$miner = 5;
    $rand = rand( 1, 22 );
if ( $turns > $user['uAttackTurns'] ) {
        echo "You don't have enough turns.";
}   
    $rand = rand( 1, 22 );
 if ( $excav1 > $user['uExcavation2'] ) {
}   
   elseif ( $rand == 1 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php
    }
    elseif ( $rand == 2 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany2,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php

        }
        if ( $excav2 = $user['uExcavation2'] ) {
}   
   elseif ( $rand == 1 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
     ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php
    }
    elseif ( $rand == 2 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php

    }
            if ( $rand == 3 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uWeapon42=uWeapon42+$zoidmany,uAttackTurns=uAttackTurns+'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>You see something shiny in the distance, What is that you wonder?</b></center><br /><?php
        ?><center><b>You just found a fully working <?=$wp_42_nm?>!<img src="<?=$wp_42_image?>"/></b></center><br /><?php
        ?><center><b>No need for excavation tools here, This bad boy runs!</b></center><br /><?php
    }
         if ( $fight2 > $defensetotal ) {
}   
   elseif ( $rand == 4 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive3?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php
    }
    if ( $fight2 < $defensetotal ) {
}   
   elseif ( $rand == 4 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake2?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php
    }
             if ( $fight1 > $defensetotal ) {
}   
   elseif ( $rand == 5 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive2?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php
    }
    if ( $fight1 < $defensetotal ) {
}   
   elseif ( $rand == 5 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake1?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php
    }
    if ( $rand == 6 || $rand == 7 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$gold1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just got ambushed. You loose 50 gold!</b></center><br /><?php
    }
            if ( $rand == 8 || $rand == 9 || $rand == 10 || $rand == 11  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>After a long hard journey you come up empty handed!</b></center><br /><?php
    }
    if ( $excav1 > $user['uExcavation2'] ) {
}   
   elseif ( $rand == 12 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uEleshotbrhinosweap=uEleshotbrhinosweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/>You decide to keep it!</b></center><br /><?php
    }
    if ( $excav2 = $user['uExcavation2'] ) {
}   
   elseif ( $rand == 12 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php
     ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php
    }
         if ( $fight3 > $defensetotal ) {
}   
   elseif ( $rand == 13 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive4,uWeapon48=uWeapon48+$zoidmany,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a group of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php
        ?><center><b>You managed to fend them off and scored a nice <?=$goldgive4?> gold!</b></center><br /></b></center><br /><?php
        ?><center><b>You also managed to take a fully working <?=$wp_48_nm?>, <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php
    }
    if ( $fight3 < $defensetotal ) {
}   
   elseif ( $rand == 13 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold-$goldtake3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You were attacked by a pack of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /><?php
        ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake3?> Gold!</b></center><br /><?php
        ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php
        ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php
    }
        if ( $rand == 14 || $rand == 15 || $rand == 16 || $rand == 17  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET ugold=ugold+$goldgive1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just stumbled across <?=$goldgive1?> Gold. You decide to keep it!</b></center><br /><?php
    }
        if ( $rand == 18 || $rand == 19 || $rand == 20 || $rand == 21  ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uMiners=uMiners+$miner,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just found <?=$miner?> miners, your forcing them to join you!</b></center><br /><?php
    }
if ( $turns > $user['uAttackTurns'] ) {
}   
   elseif ( $rand == 22 ) {
        $rand_cash = rand( 1, 50 );
        $db->query( "UPDATE users SET uAttackTurns=uAttackTurns-$turns,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" );

 ?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php
        ?><center><b>You just lost an additional <?=$turns?>. Better luck next time!</b></center><br /><?php
    }

require 'includes/footer.php';

?>

4 个答案:

答案 0 :(得分:1)

那随机的内容应该在里面,你可以“这个”

if (condition)
 {
 //code
 }
 //another code
elseif (condition)
 {
 //code
 }

所以你应该在这里更改你的代码:

if ( $turns > $user['uAttackTurns'] ) {
        echo "You don't have enough turns.";
        $rand = rand( 1, 22 );
}       
 elseif
 //code...

编辑:

其他方面没有条件,所以

else(condition)
{
//code
}

会产生另一个错误。如果其他一切都失败了,那么最后的其他事情就会完成。

答案 1 :(得分:0)

错误非常简洁。 &#34;意想不到的T_ELSEIF&#34; - 我怎么能让这个更简单?有一个没有预料到的,不应该在那里,是在错误的地方......

你没有提供行或代码,但我猜这是:

if ( $turns > $user['uAttackTurns'] ) {
        echo "You don't have enough turns.";
}   
    $rand = rand( 1, 22 );
 elseif ( $excav1 > $user['uExcavation2'] ) {
}   

所以要做其他事,elseif等,你需要从一个花括号跟随到另一个...

if (something)
  {
    whatever
  }
elseif (something else)
 {
   whatever else
 }

另外,我没有看到你在if / elseif中实际使用了$rand var,那么是否有一些丢失的代码?如果你需要在每个if / else上,把它放在elseif中。

答案 2 :(得分:0)

这是因为您在第一个&#39; if&#39;之间有声明$rand = rand( 1, 22 );。和第一个&#39; elseif&#39;。 &#39; elseif&#39;需要直接关注&#39; if&#39;中间没有任何陈述。

答案 3 :(得分:0)

用户获得更多轮次,因为您没有做任何阻止他们这样做的事情。在第一个else {}语句之后使用if将其余代码放入其中:

if( $turns > $user['uAttackTurns'] ) {
    echo "You don't have enough turns.";
}
else {

    /*** Carry on As Usual ***/
}

如果$turns 大于 $user['uAttackTurns'],这将阻止任何其他代码运行。

此外,您无需重新定义$rand = rand( 1, 22);。您在上面声明它,并在第一个if语句之后再次声明它。