- Joined
- Aug 6, 2009
- Messages
- 2,146
- Reaction score
- 438
My friend says that pyramid If...Else is worse and might make script go nuts. On other side Else If is better, he says.
Example of Pyramid If...Else
Example of Else If:
Is my friend stupid and says crap or I have been doing if...else in worst way all time?
Example of Pyramid If...Else
PHP:
if ( mssql_num_rows( $checkUsername ) > 0 )
{
showMessage( "error", "Such username is taken.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $username ) < 6 || strlen( $username ) > 12 )
{
showMessage( "error", "Username lenght must be between 6 and 12 characters long.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $password ) < 6 || strlen( $password ) > 12 )
{
showMessage( "error", "Password lenght must be between 6 and 12 characters long.", 3, "index.php?module=signup" );
}
else
{
if ( !isValidEmail( $email ) )
{
showMessage( "error", "Please enter valid email address.", 3, "index.php?module=signup" );
}
else
{
if ( $gender != 0 || $gender != 1 )
{
showMessage( "error", "Dear hacker, your gender must be 0 or 1.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $question ) < 10 )
{
showMessage( "error", "Question must be at least 10 characters long.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $answer ) < 3 )
{
showMessage( "error", "Answer must be at least 3 characters long.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $name ) < 3 )
{
showMessage( "error", "Your name must be at least 3 characters long.", 3, "index.php?module=signup" );
}
else
{
if ( strlen( $zipcode ) != 5 )
{
showMessage( "error", "Zip code must be 5 numbers long.", 3, "index.php?module=signup" );
}
else
{
$t_id_idx = 0; $t_propid = 0;
$result = mssql_query( "SELECT id_idx, propid FROM lunamember..chr_log_info" );
while($row = mssql_fetch_array($result)){
if($row['id_idx'] > $t_id_idx){
$t_id_idx = $row['id_idx'];
}
if($row['propid'] > $t_propid){
$t_propid = $row['propid'];
}
}
$t_id_idx++;
$t_propid++;
$insertUser = mssql_query( "INSERT INTO lunamember..chr_log_info (id_idx, propid, id_loginid, id_passwd, id_sexType) VALUES ('$t_id_idx', '$t_propid', '$username', '$password', '$gender');" );
if ( $insertUser )
{
$insertUserPlus = mssql_query( "INSERT INTO lunamember..chr_log_info_plus (id_idx, id_loginid, id_pw_Q, id_pw_A, id_name, id_zipcode, id_email) VALUES ('$t_id_idx', '$username', '$question', '$answer', '$name', '$zipcode', '$email');" );
showMessage( "success", "Account has been created. Enjoy Athens Luna Online", 3, "index.php?module=news" );
$_SESSION['user_idx'] = $t_id_idx;
$_SESSION['logged_in'] = true;
if ( $insertUserPlus )
{
showMessage( "success", "Additional info has been inserted as well." );
}
else
{
showMessage( "success", "There was a problem with inserting additional information. You can change/add your additional information in game panel." );
}
}
else
{
showMessage( "error", "Weird error occured. Tell admin that he has problem in registration script." );
}
}
}
}
}
}
}
}
}
}
Example of Else If:
PHP:
if ( $crap == true )
{
echo "Crap is true";
}
else if ( $pee == ture )
{
echo "Pee is true";
}
else
{
echo "Neither crap or pee is true";
}
Is my friend stupid and says crap or I have been doing if...else in worst way all time?

