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?
[code]
<?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";
}
?>
[/code]
Thank you for your help,
jfcby
[snip]
> Switch ($gpg){
>
> Case $gpg == 'pd' && $gnb == 1:
[snip]
You don't understand the switch/case syntax:
http://us2.php.net/manual/en/control-structures.switch.php
> 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'
No, it's not. You will need to use a series of if/else if statements.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
Please do not insert bbcode tags in Usenet messages. This is it not a
fancy HTML forum.
> <?php
> $gpg = $_GET["pg"];
> $gnb = $_GET["nb"];
These values may not exist. Try this instead:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
$gpg = isset($_GET['pg']) ? $_GET['pg'] : NULL;
$gnb = isset($_GET['nb']) ? $_GET['nb'] : NULL;
> Switch ($gpg){
Perhaps it's a pet peeve of mine but my eyes bleed when I see PHP
control structures in sentence case... :)
>
> Case $gpg == 'pd'&& $gnb == 1:
Right, this is a boolean expression so it will return either TRUE or
FALSE. You can *never* get a match: even if $gpg equals 'pd' and $gnb
equals '1', the expression is TRUE, which is different from 'pd'. I
presume you want this:
http://es.php.net/manual/en/control-structures.if.php
http://es.php.net/manual/en/control-structures.else.php
http://es.php.net/manual/en/control-structures.elseif.php
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--