Php Switch Case [message #169372] |
Wed, 08 September 2010 18:54 |
jfcby
Messages: 2 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
I'm trying to get this php script to either include a web page,
redirect to another webpage, or echo text. I have this page in the
main www folder on the server.
My problem is if I type the webpage address like so www.ebooktaught.com/prodtest.php
then it displays the first switch case instead of the default.
How can I get the following script to:
1. After I type in www.ebooktaught.com/prodtest.php it will display
the default echo?
2. How can I get the script to work if I type in
www.ebooktaught.com/prodtest.php?pg=pd&nb=2 for it to display the
second switch case?
<?php
$gpg = $_GET["pg"];
$gnb = $_GET["nb"];
Switch ($gpg){
Case $gpg == 'pd' && $gnb == 1:
echo "Product Page = " . $_GET['pg'] . " & Product Page # = " .
$_GET['nb'];
break;
Case $gpg == 'pd' && $gnb == 2:
echo "Product Page = " . $_GET['pg'] . " & Product Page # = " .
$_GET['nb'];
break;
Case $gpg == 'sp' && $gnb == 1:
echo "Product Page = " . $_GET['pg'] . " & Product Page # = " .
$_GET['nb'];
break;
Case $gpg == 'sp' && $gnb == 2:
echo "Product Page = " . $_GET['pg'] . " & Product Page # = " .
$_GET['nb'];
break;
default:
echo "Default";
}
?>
Thank you for your help,
jfcby
|
|
|
|
Re: Php Switch Case [message #169375 is a reply to message #169373] |
Wed, 08 September 2010 19:20 |
jfcby
Messages: 2 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
On Sep 8, 3:10 pm, matt <matthew.leonha...@gmail.com> wrote:
> You don't understand the switch/case syntax:http://us2.php.net/manual/en/control-structures.switch.php
matt,
I've read through that website and there are no examples of what I'm
trying to do.
This is what I'm trying to do. I want to be able to type in a web
address like so www.ebooktaught.com/prodtest.php?pg=pd&nb=2 and have
my php switch case statement display the correct information. Is this
possible with a switch case statement and where can I find some
examples of the correct way to do it because the link you provided
does not show how to do that?
Thank you for your help,
jfcby
|
|
|
Re: Php Switch Case [message #169376 is a reply to message #169375] |
Wed, 08 September 2010 19:58 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
jfcby wrote:
> On Sep 8, 3:10 pm, matt <matthew.leonha...@gmail.com> wrote:
>
>> You don't understand the switch/case syntax:http://us2.php.net/manual/en/control-structures.switch.php
>
> matt,
>
> I've read through that website and there are no examples of what I'm
> trying to do.
>
> This is what I'm trying to do. I want to be able to type in a web
> address like so www.ebooktaught.com/prodtest.php?pg=pd&nb=2 and have
> my php switch case statement display the correct information. Is this
> possible with a switch case statement and where can I find some
> examples of the correct way to do it because the link you provided
> does not show how to do that?
>
Switch (x) takes VALUES OF (x) as the arguments in each 'case'
> Thank you for your help,
> jfcby
|
|
|
Re: Php Switch Case [message #169385 is a reply to message #169375] |
Thu, 09 September 2010 06:30 |
Tim Roberts
Messages: 2 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
jfcby <jamesfc30(at)gmail(dot)com> wrote:
>
> This is what I'm trying to do. I want to be able to type in a web
> address like so www.ebooktaught.com/prodtest.php?pg=pd&nb=2 and have
> my php switch case statement display the correct information. Is this
> possible with a switch case statement...
No, it's not. You will need to use a series of if/else if statements.
--
Tim Roberts, timr(at)probo(dot)com
Providenza & Boekelheide, Inc.
|
|
|
|