Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] problem with if statement


[SOLVED] problem with if statement

Reply
  #1 (permalink)  
Old 04-17-08, 11:32 AM
NationVoice NationVoice is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] problem with if statement

I'm having some issues with the following code. I have a habbit of using 'or' in my if statements & was told to use || but it still doesn't seem to be working. Any help would be great.

PHP Code:

if ($ignore != "1") {
                                if ((
$plan == "41") || ($plan == "46") || ($plan == "92") || ($plan == "104")) {
                                        
$plan "400";
                                } elseif ((
$plan == "40") || ($plan == "45") || ($plan == "91") || ($plan == "103")) {
                                        
$plan "350";
                                } elseif ((
$plan == "39") || ($plan == "44") || ($plan == "90") || ($plan == "102")) {
                                        
$plan "300";
                                } else if ((
$plan == "38") || ($plan == "43") || ($plan == "89") || ($plan == "101")) {
                                        
$plan "250";
                                } elseif ((
$plan == "23") || ($plan == "18") || ($plan == "83") || ($plan == "99")) {
                                        
$plan "200";
                                } elseif ((
$plan == "37") || ($plan == "42") || ($plan == "88") || ($plan == "100")) {
                                        
$plan "150";
                                } elseif ((
$plan == "17") || ($plan == "22") || ($plan == "87") || ($plan == "98")) {
                                        
$plan "100";
                                } elseif ((
$plan == "82") || ($plan == "76") || ($plan == "94") || ($plan == "106")) {
                                        
$plan "75";
                                } elseif ((
$plan == "16") || ($plan == "20") || ($plan == "85") || ($plan == "97")) {
                                        
$plan "50";
                                } elseif ((
$plan == "15") || ($plan == "21") || ($plan == "86") || ($plan == "96")) {
                                        
$plan "25";
                                } elseif ((
$plan == "14") || ($plan == "19") || ($plan == "61") || ($plan == "62") || ($plan == "84") || ($plan == "95")) {
                                        
$plan "15";
                                } elseif ((
$plan == "63") || ($plan == "64") || ($plan == "59") || ($plan == "60") || ($plan == "105") || ($plan == "93")) {
                                        
$plan "10";
                                } else {
                                        
$plan "Unknown";
                                }
                        } 
It's not spitting out any errors, its just not working properly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-17-08, 11:48 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Try this:

PHP Code:

if ($ignore != 1){

    if(
$plan == 41 || $plan == 46 || $plan == 92 || $plan == 104){
        
        
$plan 400;
    }elseif(
$plan == 40 || $plan == 45 || $plan == 91 || $plan == 103){
        
        
$plan 350;
    }elseif(
$plan == 39 || $plan == 44 || $plan == 90 || $plan == 102){
        
        
$plan 300;
    }elseif(
$plan == 38 || $plan == 43 || $plan == 89 || $plan == 101){
    
        
$plan 250;
    }elseif(
$plan == 23 || $plan == 18 || $plan == 83 || $plan == 99){
        
        
$plan 200;
    }elseif(
$plan == 37 || $plan == 42 || $plan == 88 || $plan == 100){
        
        
$plan 150;
    }elseif(
$plan == 17 || $plan == 22 || $plan == 87 || $plan == 98){
        
        
$plan 100;
    }elseif(
$plan == 82 || $plan == 76 || $plan == 94 || $plan == 106){
        
        
$plan 75;
    }elseif(
$plan == 16 || $plan == 20 || $plan == 85 || $plan == 97){
        
        
$plan 50;
    }elseif(
$plan == 15 || $plan == 21 || $plan == 86 || $plan == 96){
        
        
$plan 25;
    }elseif(
$plan == 14 || $plan == 19 || $plan == 61 || $plan == 62 || $plan == 84 || $plan == 95){
        
        
$plan 15;
    }elseif(
$plan == 63 || $plan == 64 || $plan == 59 || $plan == 60 || $plan == 105 || $plan == 93) {
        
        
$plan 10;
    }else{
        
        
$plan 'Unknown';
    }

__________________
Can you think outside the box but remain inside the box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-17-08, 11:56 AM
a.struct a.struct is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure what you're trying to do, but i did notice that at the end of the code, the final else value sets $plan to a string, rather than an integer. Now, I know php is much more forgiving about this than c++, which is my native language. Try setting the final else to set $plan to "0" rather than unknown. Or, provide a little more info about what you're trying to do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-17-08, 12:08 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Use either a switch statement or use arrays and search the arrays for the correct plan. This method is fairly ugly and impractical really
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-17-08, 12:14 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Jay6390 View Post
Use either a switch statement or use arrays and search the arrays for the correct plan. This method is fairly ugly and impractical really
I second that.
__________________
Can you think outside the box but remain inside the box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-17-08, 12:20 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
And since I was bored, here's a working example of how it would be done with arrays
PHP Code:

$plan='23';
$foundplan false;

$plans = array();
$plans[400]     = array(41,46,92,104);
$plans[350]     = array(40,45,91,103);
$plans[300]     = array(39,44,90,102);
$plans[250]     = array(38,43,89,101);
$plans[200]     = array(23,18,83,99);
$plans[150]     = array(37,42,88,100);
$plans[100]     = array(17,22,87,98);
$plans[75]      = array(82,76,94,106);
$plans[50]      = array(16,20,85,97);
$plans[25]      = array(15,21,86,96);
$plans[15]      = array(14,19,61,62);
$plans[10]      = array(63,64,59,60);
foreach(
$plans as $k=>$v)
{
    if(
array_search(strval($plan),$v)!==false)
    {
        
$foundplan $k;
        break;
    }
}

$plan =($foundplan)?$foundplan:'Unknown';
echo 
$plan
Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName

Last edited by Jay6390; 04-17-08 at 12:23 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-17-08, 12:23 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Such as:

PHP Code:


if ($ignore != 1){

    switch(
$plan){
        
        default:
            
            
$plan 'Unknown'// Should set to 0 like a.struck suggested.
        
break;
        
        case 
41:
        case 
46:
        case 
92:
        case 
104:
            
            
$plan 400;
        break;
        
        case 
40:
        case 
45:
        case 
91:
        case 
103:
            
            
$plan 350;
        break;
        
        case 
39:
        case 
44:
        case 
90:
        case 
102:
            
            
$plan 300;
        break;
        
        case 
38:
        case 
43:
        case 
89:
        case 
101:
            
            
$plan 250;
        break;
        
        case 
23:
        case 
18:
        case 
83:
        case 
99:
            
            
$plan 200;
        break;
        
        case 
37:
        case 
42:
        case 
88:
        case 
100:
        
            
$plan 150;
        break;
        
        case 
17:
        case 
22:
        case 
87:
        case 
98:
            
            
$plan 100;
        break;
        
        case 
82:
        case 
76:
        case 
94:
        case 
106:
            
            
$plan 75;
        break;
        
        case 
16:
        case 
20:
        case 
85:
        case 
97:
            
            
$plan 50;
        break;
        
        case 
15:
        case 
21:
        case 
86:
        case 
96:
            
            
$plan 25
        
break;
        
        case 
14:
        case 
19:
        case 
61:
        case 
62:
        case 
84:
        case 
95:
            
            
$plan 15;
        break;
        
        case 
63:
        case 
64:
        case 
59:
        case 
60:
        case 
105:
        case 
93:
            
            
$plan 10;
        break;
    }

__________________
Can you think outside the box but remain inside the box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-17-08, 12:24 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
HAHAHAHA you go the short way I'll got the long way.
__________________
Can you think outside the box but remain inside the box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 04-17-08, 12:24 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
I was going to do that one, but I realised it's just as long winded as the if statements really, just a bit more presentable
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 04-17-08, 12:31 PM
NationVoice NationVoice is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
That did it. Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 04:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 06:18 AM
Count problem kasic ASP.NET 1 10-20-04 01:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 10:13 AM
SQL Statement problem jetskibum ASP 1 08-16-04 07:41 AM


All times are GMT -5. The time now is 01:10 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.