Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Is there an IF limit?
Old 07-10-2010, 08:21 AM Is there an IF limit?
Junior Talker

Posts: 3
Name: Phil
Trades: 0
I have written the following script as part of a dynamic forum signature.

Code:
// Play Style Script ----------------------------------------------------------
plytype="G.I. Soldier DEF";

plygistyp="G.I. Soldier";
plyairtyp="Airborne";
plymartyp="Marine";
plycomtyp="Commando";
plysprtyp="Sniper";
plysabtyp="Saboteur";
plyarityp="Armoured Infantry";
plyobstyp="Observer";
plyfobtyp="Forward Observer";
plycchtyp="Crew Chief";
plycmetyp="Crew Medic";
plycmntyp="Crewman";

if((spectype==speccqbtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==specfamtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==specsprtyp)&&(exptype==expexptyp)) {plytype=plysabtyp;}
if((spectype==speccqbtyp)&&(exptype==expmfctyp)) {plytype=plyfobtyp;}
if((spectype==specfamtyp)&&(exptype==expmfctyp)) {plytype=plyfobtyp;}
if((spectype==specarmtyp)&&(exptype==expfretyp)) {plytype=plycchtyp;}
if((spectype==specsprtyp)&&(exptype==expffatyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expfrptyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expfretyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expanttyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expaidtyp)) {plytype=plysprtyp;}
if((spectype==specsprtyp)&&(exptype==expmfctyp)) {plytype=plyobstyp;}
if((spectype==specairtyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specarmtyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specbottyp)&&(exptype==expffatyp)) {plytype=plycmetyp;}
if((spectype==specairtyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
if((spectype==specarmtyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
if((spectype==specbottyp)&&(exptype==expfrptyp)) {plytype=plycmntyp;}
else {plytype=plygistyp;}

plytype_color = "ffffff";

text(x: col7, y:line2_y, text: concat(plytype), size:12, align:"left", font:damaged, color:plytype_color);
You'll notice I have used an IF,ELSE format (with a lot of IFs!).

The problem I have is that the script functions perfectly when I use 7 IFs followed by an ELSE.

However, when I exceed this apparent 7 IF limit, the script reverts to giving the ELSE value ({plytype=plygistyp;})


- Is there a limit to the number of IF statements that can be used in an IF,ELSE format?

- Can anyone offer any help/solutions to my problem, please?

- Could this be done better using some form of array?
Zener25 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-10-2010, 08:52 AM Re: Is there an IF limit?
Junior Talker

Posts: 3
Name: Phil
Trades: 0
...I have since solved this problem with IF,ELSEIF,ELSE Ooops!
Zener25 is offline
Reply With Quote
View Public Profile
 
Old 07-10-2010, 09:02 AM Re: Is there an IF limit?
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
I don't understand your code, at the begining are these supposed to be variables being assigned values?:

Quote:
Originally Posted by Zener25 View Post
plytype="G.I. Soldier DEF";

plygistyp="G.I. Soldier";
plyairtyp="Airborne";
plymartyp="Marine";
plycomtyp="Commando";
plysprtyp="Sniper";
plysabtyp="Saboteur";
plyarityp="Armoured Infantry";
plyobstyp="Observer";
plyfobtyp="Forward Observer";
plycchtyp="Crew Chief";
plycmetyp="Crew Medic";
plycmntyp="Crewman";

If so then why aren't the variables starting with a $ symbol? And in your script I don't understand something like this:

PHP Code:
if((spectype==specfamtyp)&&(exptype==expexptyp)) {
    
plytype=plysabtyp;

For example what is "spectype", is it a variable, string, what? If it's a variable it needs to start with a dollar sign and if it's a string it needs to be within single or double quotations.

As for there being any limits to using the IF statement, no there aren't any, what you should do is use it in this manner:

PHP Code:
if () {
   
// something
}
elseif() {
   
// something else
}
elseif() {
   
// something else again
}
else() {
  
// something else altogether

Use as many elseifs as you want in there.
__________________

Please login or register to view this content. Registration is FREE

Last edited by Marik; 07-10-2010 at 09:03 AM..
Marik is offline
Reply With Quote
View Public Profile
 
Old 07-10-2010, 09:05 AM Re: Is there an IF limit?
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Quote:
Originally Posted by Zener25 View Post
...I have since solved this problem with IF,ELSEIF,ELSE Ooops!
He he he, beat my post by minutes
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 07-10-2010, 11:19 AM Re: Is there an IF limit?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Oh my god....
Please, use a switch statement in those case:
http://www.php.net/manual/en/control...res.switch.php
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Is there an IF limit?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85694 seconds with 12 queries