FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Php Switch Case
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Php Switch Case [message #169372] Wed, 08 September 2010 18:54 Go to next message
jfcby is currently offline  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 #169373 is a reply to message #169372] Wed, 08 September 2010 19:10 Go to previous messageGo to next message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma: 0
Member
On Sep 8, 2:54 pm, jfcby <jamesf...@gmail.com> wrote:
> 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.

[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
Re: Php Switch Case [message #169375 is a reply to message #169373] Wed, 08 September 2010 19:20 Go to previous messageGo to next message
jfcby is currently offline  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 Go to previous messageGo to next message
The Natural Philosoph is currently offline  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 Go to previous messageGo to next message
Tim Roberts is currently offline  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.
Re: Php Switch Case [message #169388 is a reply to message #169372] Thu, 09 September 2010 07:10 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 08/09/2010 20:54, jfcby escribió/wrote:
> [code]

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
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Another heredoc question
Next Topic: Downloading files, without internet renumbering...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 02:38:54 GMT 2024

Total time taken to generate the page: 0.02272 seconds