[PHP] Using if(isset()) with $_GET and switch and default

2010-05-21 Thread MuFei
Hi,
I'm still new to PHP and everyday I learn something new.
Today I was trying to make some script using the switch statement but
I have some issue that I don't know how to get around it.
It's a simple test script that contain only one file, it has some
questions that I want only one question appear per time then go to the
next question when clicking on the submit button, I used switch for
that, but when I get the first page, I got a notice which says:
Notice: Undefined index: question in path\test.php on line 56
So I used if(isset($_GET[''])) but then the default value of the
switch does not show up in the first page and I get the first page
blank.

1- Is there anyway that I can use the default value of the switch
without getting the note?
Or
2- Is there anyway that I can use the default value of the switch with
the if(isset()) and show the first page?

Here is the content of the script that I hope you can help me with:
(please note that it's not finished yet and it's so simple)
(The if(isset()) is commented)




 A- Software 
 B- Hypertext
Preprocessor, Scripting Server side programming language 
 C- Client side
programming language 
';
$answer1 = 'b';

$question2 = '2- What is PHP used for?
 A- For web 
 B- For Computers 
 C- For Designing 
';
$answer2 = 'a';

$question3 = '3- What is good about PHP?
 A- It\'s
Designed and created for the web 
 B- It\'s Free 
 C- It supports
different Databases 
 D- It\'s not
an Oriented Programming language 
';
$answer3_1 = 'a';
$answer3_2 = 'b';
$answer3_3 = 'c';

$question4 = '4- What does PHP stands for?
 A- Perl Hypertext
Programming 
 B- Personal Home
Page 
';
$answer4 = 'b';

$question5 = '5- Who created PHP?
 A- Andi Gutmans 
 B- Zeev Suraski 
 C- Rasmus Lerdorf 
';
$answer5 = 'c';
?>







  
' .
$question1 .'';
break;

case '2':
echo '' .
$question2 .'';
break;

case '3':
echo '' .
$question3 .'';
break;

case '4':
echo '' .
$question4 .'';
break;

case '5':
echo '' .
 $question5 .'';
break;

case 'Results':
echo 'You results are: Go to the
home page and do the test again!';
break;

default:
echo 'Welcome to PHP simple 
test, Please click on Start button
to begin you test. 
Click Here to Begin!';
break;
}
//}
?>






Thanks for your help guys! ^^

MuFei

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using if(isset()) with $_GET and switch and default

2010-05-21 Thread MuFei
Thanks, Adam
The first option (setting the GET) works great.
I already know about taking the default out of the switch and putting
it in an else statement, but I want to work with the default inside
the switch. And of course I wanted to do it without turning off
E_NOTICE warnings

Thanks again for your help :)

On Fri, May 21, 2010 at 11:18 PM, Adam Richardson  wrote:
> On Fri, May 21, 2010 at 3:24 PM, MuFei  wrote:
>>
>> Hi,
>> I'm still new to PHP and everyday I learn something new.
>> Today I was trying to make some script using the switch statement but
>> I have some issue that I don't know how to get around it.
>> It's a simple test script that contain only one file, it has some
>> questions that I want only one question appear per time then go to the
>> next question when clicking on the submit button, I used switch for
>> that, but when I get the first page, I got a notice which says:
>> Notice: Undefined index: question in path\test.php on line 56
>> So I used if(isset($_GET[''])) but then the default value of the
>> switch does not show up in the first page and I get the first page
>> blank.
>>
>> 1- Is there anyway that I can use the default value of the switch
>> without getting the note?
>>    Or
>> 2- Is there anyway that I can use the default value of the switch with
>> the if(isset()) and show the first page?
>>
>> Here is the content of the script that I hope you can help me with:
>> (please note that it's not finished yet and it's so simple)
>> (The if(isset()) is commented)
>>
>> 
>>
>> >        // List of test questions and their answers in variables
>>        $question1 = '1- What is PHP?
>>                                                > name="q1a" value="a" /> A- Software 
>>                                                > name="q1a" value="b" /> B- Hypertext
>> Preprocessor, Scripting Server side programming language 
>>                                                > name="q1a" value="c" /> C- Client side
>> programming language 
>>                                                > name="sumbit" value="Question 2" />';
>>        $answer1 = 'b';
>>
>>        $question2 = '2- What is PHP used for?
>>                                                > name="q2a" value="a" /> A- For web 
>>                                                > name="q2a" value="b" /> B- For Computers 
>>                                                > name="q2a" value="c" /> C- For Designing 
>>                                                > name="sumbit" value="Question 3" />';
>>        $answer2 = 'a';
>>
>>        $question3 = '3- What is good about PHP?
>>                                                > name="q3a[a]" value="a" /> A- It\'s
>> Designed and created for the web 
>>                                                > name="q3a[b]" value="b" /> B- It\'s Free 
>>                                                > name="q3a[c]" value="c" /> C- It supports
>> different Databases 
>>                                                > name="q3a[d]" value="d" /> D- It\'s not
>> an Oriented Programming language 
>>                                                > name="sumbit" value="Question 4" />';
>>        $answer3_1 = 'a';
>>        $answer3_2 = 'b';
>>        $answer3_3 = 'c';
>>
>>        $question4 = '4- What does PHP stands for?
>>                                                > name="q4a" value="a" /> A- Perl Hypertext
>> Programming 
>>                                                > name="q4a" value="b" /> B- Personal Home
>> Page 
>>                                                > name="sumbit" value="Question 5" />';
>>        $answer4 = 'b';
>>
>>        $question5 = '5- Who created PHP?
>>                                                > name="q5a" value="a" /> A- Andi Gutmans 
>>                                                > name="q5a" value="b" /> B- Zeev Suraski 
>>            

Re: [PHP] Using if(isset()) with $_GET and switch and default

2010-05-21 Thread MuFei
Hi Ashley,
Your way works also great, But I have some question thought:
When I only use the first half of the code you suggested:
$question = (isset($_GET['question']));
then use the $question in the switch it works as I want it.
If I use the whole code( $question =
(isset($_GET['question']))?$_GET['question']:'some default value
here';), the results also are the same.
My question is:
What is the code from the "?"sign to the end for?
Are you pointing to use that in the url? And the value that I'll put
it there is to be used in the url? or you mean something else?
I'm asking this because as I said before it works with the first half
of the code just as it works with the full code.

Sorry, but I'm a little bit confused as there are still a lot of
things which I don't know about yet  ^^

Thanks again, Ashley





On Fri, May 21, 2010 at 11:20 PM, Ashley Sheridan
 wrote:
>
> On Fri, 2010-05-21 at 16:18 -0400, Adam Richardson wrote:
>
> On Fri, May 21, 2010 at 3:24 PM, MuFei  wrote:
>
> > Hi,
> > I'm still new to PHP and everyday I learn something new.
> > Today I was trying to make some script using the switch statement but
> > I have some issue that I don't know how to get around it.
> > It's a simple test script that contain only one file, it has some
> > questions that I want only one question appear per time then go to the
> > next question when clicking on the submit button, I used switch for
> > that, but when I get the first page, I got a notice which says:
> > Notice: Undefined index: question in path\test.php on line 56
> > So I used if(isset($_GET[''])) but then the default value of the
> > switch does not show up in the first page and I get the first page
> > blank.
> >
> > 1- Is there anyway that I can use the default value of the switch
> > without getting the note?
> >Or
> > 2- Is there anyway that I can use the default value of the switch with
> > the if(isset()) and show the first page?
> >
> > Here is the content of the script that I hope you can help me with:
> > (please note that it's not finished yet and it's so simple)
> > (The if(isset()) is commented)
> >
> > 
> >
> >  >// List of test questions and their answers in variables
> >$question1 = '1- What is PHP?
> > > name="q1a" value="a" /> A- Software 
> > > name="q1a" value="b" /> B- Hypertext
> > Preprocessor, Scripting Server side programming language 
> > > name="q1a" value="c" /> C- Client side
> > programming language 
> > > name="sumbit" value="Question 2" />';
> >$answer1 = 'b';
> >
> >$question2 = '2- What is PHP used for?
> > > name="q2a" value="a" /> A- For web 
> > > name="q2a" value="b" /> B- For Computers 
> > > name="q2a" value="c" /> C- For Designing 
> > > name="sumbit" value="Question 3" />';
> >$answer2 = 'a';
> >
> >$question3 = '3- What is good about PHP?
> > > name="q3a[a]" value="a" /> A- It\'s
> > Designed and created for the web 
> > > name="q3a[b]" value="b" /> B- It\'s Free 
> > > name="q3a[c]" value="c" /> C- It supports
> > different Databases 
> > > name="q3a[d]" value="d" /> D- It\'s not
> > an Oriented Programming language 
> > > name="sumbit" value="Question 4" />';
> >$answer3_1 = 'a';
> >$answer3_2 = 'b';
> >$answer3_3 = 'c';
> >
> >$question4 = '4- What does PHP stands for?
> > > name="q4a" value="a"

Re: [PHP] Using if(isset()) with $_GET and switch and default

2010-05-22 Thread MuFei
Yes, I got it now.
Thanks Daniel
Thanks everyone!


On Sat, May 22, 2010 at 12:08 AM, Daniel P. Brown
 wrote:
> On Fri, May 21, 2010 at 17:02, MuFei  wrote:
>> Hi Ashley,
>> Your way works also great, But I have some question thought:
>> When I only use the first half of the code you suggested:
>> $question = (isset($_GET['question']));
>> then use the $question in the switch it works as I want it.
>> If I use the whole code( $question =
>> (isset($_GET['question']))?$_GET['question']:'some default value
>> here';), the results also are the same.
>> My question is:
>> What is the code from the "?"sign to the end for?
>
>    Ash gave you a ternary operator example.
>
>        http://php.net/manual/en/language.operators.comparison.php
>
> --
> 
> daniel.br...@parasane.net || danbr...@php.net
> http://www.parasane.net/ || http://www.pilotpig.net/
> We now offer SAME-DAY SETUP on a new line of servers!
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php