Gossamer Forum
Home : General : Internet Technologies :

switch() function problem

Quote Reply
switch() function problem
I'm having an issue with the switch function. I'm getting this error:

Parse error: parse error, unexpected T_DEFAULT in C:\blah blah on line 183

Code:
switch($request_pagestyle) {
case default:
$sel_default == "select='selected'";
$sel_PTMaroon == "";
break;
case PTMaroon:
$sel_default == "";
$sel_PTMaroon == "select='selected'";
break;
}


It seems pretty basic and simple yet I'm getting this error. Any help is, as usual, much appreciated.
Quote Reply
Re: [JoFrRi] switch() function problem In reply to
A few suggestions:

1) case statements need to have variable values quoted (unless they are numbers or booleans) - this is almost certainly what's causing the error message

2) your default case should always come last, so that it gets evaluated only if none of the other cases were evaluated

3) using double equal signs like == is for evaluating a statement as true or false, so I assume you need to change those to single equal signs, since seemingly you want to set values

So I would change your code to:

Code:
switch($request_pagestyle) {
case 'PTMaroon':
$sel_default = "";
$sel_PTMaroon = "select='selected'";
break;

case default:
$sel_default = "select='selected'";
$sel_PTMaroon = "";
break;
}

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] switch() function problem In reply to
Thanks. I changed the double equal signs soon after along with removing "case default" and turning it into just "default" and it works great now.

switch($memPagestyle) {
default:
$editPagestyle_a = "selected='selected'";
break;
}

Thanks for responding.
Quote Reply
Re: [JoFrRi] switch() function problem In reply to
Oops - can't believe I missed that "case default"... Sorry about that, but nice job catching my mistake. Smile Glad it's working now.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund