Re: [PHP] Switch Statement

2013-09-29 Thread Aziz Saleh
What is the output?


On Sun, Sep 29, 2013 at 1:34 AM, Ethan Rosenberg 
erosenb...@hygeiabiomedical.com wrote:

 On 09/28/2013 10:53 PM, Aziz Saleh wrote:

 Ethan, can you do a var_dump instead of print_r. It might be that
 next_step
 has spaces in it causing the switch to not match.

 Aziz


  snip

 Aziz -

 Used var_dump no further information


 Ethan


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




Re: [PHP] Switch Statement

2013-09-29 Thread mrfroasty
Hello,

I suggest you put default in that switch statement and var_dump the
$_POST.That should be enough for a programmer to pin point what goes wrong.

P:S
**You might want to consider versioning your codes to go back into its
history to see what has changed.

Muhsin

On 09/29/2013 04:33 AM, Ethan Rosenberg wrote:
 Dear List -

 I have a working program.  I made one change in a switch statement,
 and it does not work.  I'm probably missing something fundamental.

 Here are some code SNIPPETS...  [please note that all my debug
 statements are at the left margin]

 Setup...

 ?php
 session_start();
 session_name(STORE);
 set_time_limit(2400);
 ini_set('display_errors', 'on');
 ini_set('display_startup_errors', 'on');
 error_reporting(-2);

 ini_set('error_reporting', 'E_ALL | E_STRICT');
 ini_set('html_errors', 'On');
 ini_set('log_errors', 'On');
 require '/home/ethan/P/wk.inc'; //password file
 $db = Store;
 $cxn =mysqli_connect($host,$user,$password,$db);
 if (!$cxn)
 {
 die('Connect Error (' . mysqli_connect_errno() . ') '
 . mysqli_connect_error());
 }// no error   
 if($_REQUEST['welcome_already_seen']!= already_seen)   
 show_welcome();
 
 //end setup
 function show_welcome() //this is the input screen
 {
 snip

 echo  input type='hidden' name='welcome_already_seen'
 value='already_seen';
 echo  input type='hidden' name='next_step' value='step20' /;

 snip
 }

 
 //end input screen

 //Switch statement

 echo 'before';
 print_r($_POST); //post#1   

 switch ( $_POST['next_step'] )
 {

 case 'step20':
 {
 pint_r($_POST);//post#2   
 echo 'step20';
 if(!empty($_POST['Cust_Num']))
 good();
 if(empty($_POST['Cust_Num']))
 bad();
 break;
 } //end step20

 snip
 } //end switch
 
 

 post#1

 beforeArray
 (
 [Cust_Num] = 123
 [Fname] =
 [Lname] =
 [Street] =
 [City] =
 [state] = NY
 [Zip] = 10952
 [PH1] =
 [PH2] =
 [PH3] =
 [Date] =
 [welcome_already_seen] = already_seen
 [next_step] = step20

 )

 Cust_Num state and Zip are as entered.

 The switch statement is never entered, since post#2 is never
 displayed, and neither good() or bad() functions are entered.   


 TIA

 Ethan





-- 
Extra details:
OSS:Gentoo Linux
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,PHP
Typo:40WPM
url:http://www.mzalendo.net
url:http://www.zanbytes.com



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



[PHP] Switch Statement

2013-09-28 Thread Ethan Rosenberg

Dear List -

I have a working program.  I made one change in a switch statement, and 
it does not work.  I'm probably missing something fundamental.


Here are some code SNIPPETS...  [please note that all my debug 
statements are at the left margin]


Setup...

?php
session_start();
session_name(STORE);
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);

ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = Store;
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= already_seen)  
  
show_welcome();

//end setup
function show_welcome() //this is the input screen
{
snip

	echo  input type='hidden' name='welcome_already_seen' 
value='already_seen';

echo  input type='hidden' name='next_step' value='step20' /;

snip
}


//end input screen

//Switch statement

echo 'before';
print_r($_POST); //post#1   

switch ( $_POST['next_step'] )
{

case 'step20':
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20

snip
} //end switch



post#1

beforeArray
(
[Cust_Num] = 123
[Fname] =
[Lname] =
[Street] =
[City] =
[state] = NY
[Zip] = 10952
[PH1] =
[PH2] =
[PH3] =
[Date] =
[welcome_already_seen] = already_seen
[next_step] = step20

)

Cust_Num state and Zip are as entered.

The switch statement is never entered, since post#2 is never displayed, 
and neither good() or bad() functions are entered.		



TIA

Ethan



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



Re: [PHP] Switch Statement

2013-09-28 Thread Aziz Saleh
Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.

Aziz


On Sat, Sep 28, 2013 at 10:33 PM, Ethan Rosenberg 
erosenb...@hygeiabiomedical.com wrote:

 Dear List -

 I have a working program.  I made one change in a switch statement, and it
 does not work.  I'm probably missing something fundamental.

 Here are some code SNIPPETS...  [please note that all my debug statements
 are at the left margin]

 Setup...

 ?php
 session_start();
 session_name(STORE);
 set_time_limit(2400);
 ini_set('display_errors', 'on');
 ini_set('display_startup_**errors', 'on');
 error_reporting(-2);

 ini_set('error_reporting', 'E_ALL | E_STRICT');
 ini_set('html_errors', 'On');
 ini_set('log_errors', 'On');
 require '/home/ethan/P/wk.inc'; //password file
 $db = Store;
 $cxn =mysqli_connect($host,$user,$**password,$db);
 if (!$cxn)
 {
 die('Connect Error (' . mysqli_connect_errno() . ') '
 . mysqli_connect_error());
 }// no error
 if($_REQUEST['welcome_already_**seen']!= already_seen)

 show_welcome();

 //end setup
 function show_welcome() //this is the input screen
 {
 snip

 echo  input type='hidden' name='welcome_already_seen'
 value='already_seen';
 echo  input type='hidden' name='next_step' value='step20' /;

 snip
 }


 //end input screen

 //Switch statement

 echo 'before';
 print_r($_POST); //post#1

 switch ( $_POST['next_step'] )
 {

 case 'step20':
 {
 pint_r($_POST); //post#2
 echo 'step20';
 if(!empty($_POST['Cust_Num']))
 good();
 if(empty($_POST['Cust_Num']))
 bad();
 break;
 } //end step20

 snip
 } //end switch



 post#1

 beforeArray
 (
 [Cust_Num] = 123
 [Fname] =
 [Lname] =
 [Street] =
 [City] =
 [state] = NY
 [Zip] = 10952
 [PH1] =
 [PH2] =
 [PH3] =
 [Date] =
 [welcome_already_seen] = already_seen
 [next_step] = step20

 )

 Cust_Num state and Zip are as entered.

 The switch statement is never entered, since post#2 is never displayed,
 and neither good() or bad() functions are entered.


 TIA

 Ethan



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




Re: [PHP] Switch Statement

2013-09-28 Thread Ethan Rosenberg

On 09/28/2013 10:53 PM, Aziz Saleh wrote:

Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.

Aziz



snip

Aziz -

Used var_dump no further information

Ethan


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



Re: [PHP] Switch statement Question

2009-01-30 Thread Thodoris


Hi, 
 
  I have a code snippet here as in the following:
 
//Switch statements between the four options 
switch($string) {

case :
$string= NOT book.author='All';
break;
default:
$string= $string . AND NOT book.author='All';
break;
}
  This code does work, but I am wondering if it is possible in the switch statement clauses for me to do something like case does not equal to a certain author name if I don't want $string with that content to be processed. or, do I always use default in this case? 
 
Thanks in advance. 
 
Alice  
_

All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail
  


Well I will have to mention that switch becomes if after all internally 
so you could always use the if statement.


I am a great fan of switch but since eclipse fail to format correctly 
embedded switch statements I am starting to use the old all good if() 
since it is the same thing. It is a matter of style actually although 
switch is slightly slower (so slightly that you can't notice in any case).


I think there was a thread in this list for this comparison a few days ago.

--
Thodoris


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



[PHP] Switch statement Question

2009-01-29 Thread Alice Wei

Hi, 
 
  I have a code snippet here as in the following:
 
//Switch statements between the four options 
switch($string) {
case :
$string= NOT book.author='All';
break;
default:
$string= $string . AND NOT book.author='All';
break;
}
  This code does work, but I am wondering if it is possible in the switch 
statement clauses for me to do something like case does not equal to a certain 
author name if I don't want $string with that content to be processed. or, do I 
always use default in this case? 
 
Thanks in advance. 
 
Alice  
_
All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

RE: [PHP] Switch statement Question

2009-01-29 Thread Boyd, Todd M.
 -Original Message-
 From: Alice Wei [mailto:aj...@alumni.iu.edu]
 Sent: Thursday, January 29, 2009 3:02 PM
 To: php-general@lists.php.net
 Subject: [PHP] Switch statement Question
 
 
 Hi,
 
   I have a code snippet here as in the following:
 
 //Switch statements between the four options
 switch($string) {
 case :
 $string= NOT book.author='All';
 break;
 default:
 $string= $string . AND NOT book.author='All';
 break;
 }
   This code does work, but I am wondering if it is possible in the
 switch statement clauses for me to do something like case does not
 equal to a certain author name if I don't want $string with that
 content to be processed. or, do I always use default in this case?

It's a bit non-conventional, but the switch block can be used like so:

switch(true) {
case (x  y):
dosomething();
break;
case (y == 0):
dosomethingelse();
break;
default:
somethingelseentirely();
break;
}

...this way, your case statements can be expressions themselves, and it
will always pick at least one of them to fire.

HTH,


// Todd

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



Re: [PHP] Switch statement Question

2009-01-29 Thread Jochem Maas
Boyd, Todd M. schreef:
 -Original Message-
 From: Alice Wei [mailto:aj...@alumni.iu.edu]
 Sent: Thursday, January 29, 2009 3:02 PM
 To: php-general@lists.php.net
 Subject: [PHP] Switch statement Question


 Hi,

   I have a code snippet here as in the following:

 //Switch statements between the four options
 switch($string) {
 case :
 $string= NOT book.author='All';
 break;
 default:
 $string= $string . AND NOT book.author='All';
 break;
 }
   This code does work, but I am wondering if it is possible in the
 switch statement clauses for me to do something like case does not
 equal to a certain author name if I don't want $string with that
 content to be processed. or, do I always use default in this case?
 
 It's a bit non-conventional, but the switch block can be used like so:
 
 switch(true) {
   case (x  y):
   dosomething();
   break;
   case (y == 0):
   dosomethingelse();
   break;
   default:
   somethingelseentirely();
   break;
 }

some people really don't like this kind of thing (hi Robbert :-)),
either way beware that the equality test is not strict, that is
to say autocasting occurs (variable type doesn't have to match)

an example:

switch (true) {
case 1:
echo did you expect this?\n; // -- this is output
break;
case true:
echo or this?\n;
break;
}



 ...this way, your case statements can be expressions themselves, and it
 will always pick at least one of them to fire.
 
 HTH,
 
 
 // Todd
 


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



[PHP] Switch Statement || Case with multiple values?

2003-03-02 Thread CF High
Hey all.

In Cold Fusion I was able to do the following:

CFSWITCH expression = #action#

CFCASE value = getUpdate,getDelete
Do Stuff
/CFCASE

/CFSWITCH

Note the comma delimited set of values for the case.  Is there a way to do
this in php?( i.e. if any of the comma delimited case values match the
switch expression, proceed with the specified case instructions)

It's kind of cumbersome breaking out 5 cases when in CF I can combine them
into one

Let me know.

--Noah



--




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



RE: [PHP] Switch Statement || Case with multiple values?

2003-03-02 Thread Martin Towell
I've been using this:

if (in_array($value, array(foo, bar, blah)))
{
  // do something
}

but if you want to use a switch/case, I don't know any easier way.

HTH
Martin

 -Original Message-
 From: CF High [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 03, 2003 1:41 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Switch Statement || Case with multiple values?
 
 
 Hey all.
 
 In Cold Fusion I was able to do the following:
 
 CFSWITCH expression = #action#
 
 CFCASE value = getUpdate,getDelete
 Do Stuff
 /CFCASE
 
 /CFSWITCH
 
 Note the comma delimited set of values for the case.  Is 
 there a way to do
 this in php?( i.e. if any of the comma delimited case values match the
 switch expression, proceed with the specified case instructions)
 
 It's kind of cumbersome breaking out 5 cases when in CF I can 
 combine them
 into one
 
 Let me know.
 
 --Noah
 
 
 
 --
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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



RE: [PHP] Switch Statement || Case with multiple values?

2003-03-02 Thread Mark Charette
Check the manual:

switch($foo)
{
case fee:
case fie:
...
break;
case fo:
...
case fum:
...
break;
}

fee  fie are tied together, fie will also run the code presented by fum ...

Even more flexible than comma delimited values ...

 -Original Message-
 From: CF High [mailto:[EMAIL PROTECTED]
 Sent: Sunday, March 02, 2003 9:41 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Switch Statement || Case with multiple values?


 Hey all.

 In Cold Fusion I was able to do the following:

 CFSWITCH expression = #action#

 CFCASE value = getUpdate,getDelete
 Do Stuff
 /CFCASE

 /CFSWITCH



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



Re: [PHP] Switch Statement || Case with multiple values?

2003-03-02 Thread Leif K-Brooks
switch($value){
   case 'foo':
   case 'bar':
   //It's either foo or bar
   break;
}
CF High wrote:

Hey all.

In Cold Fusion I was able to do the following:

CFSWITCH expression = #action#

   CFCASE value = getUpdate,getDelete
   Do Stuff
   /CFCASE
/CFSWITCH

Note the comma delimited set of values for the case.  Is there a way to do
this in php?( i.e. if any of the comma delimited case values match the
switch expression, proceed with the specified case instructions)
It's kind of cumbersome breaking out 5 cases when in CF I can combine them
into one
Let me know.

--Noah



--



 

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.


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


RE: [PHP] Switch Statement || Case with multiple values?

2003-03-02 Thread Mark Charette
Duh. make that
fo will also run the code presented by fum ...

 -Original Message-
 From: Mark Charette [mailto:[EMAIL PROTECTED]
 
 switch($foo)
 {
   case fee:
   case fie:
   ...
   break;
   case fo:
   ...
   case fum:
   ...
   break;
 }
 
 fee  fie are tied together, fie will also run the code presented 
 by fum ...
 
 Even more flexible than comma delimited values ...


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



[PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread CF High
Hey all.

Don't know if this is possible, but here goes:

I've got a simple switch statement that carries out one of several
operations based on the switch statement variable value.

Each operation has @ 50 lines of html -- do I have to echo or print all this
html!?

I'm new to PHP so pardon my ignorance here.  I'm used to the relative ease
of Cold Fusion

Thanks for any ideas/suggestions,

--Noah

--




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




RE: [PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread John W. Holmes
 I've got a simple switch statement that carries out one of several
 operations based on the switch statement variable value.
 
 Each operation has @ 50 lines of html -- do I have to echo or print
all
 this
 html!?

You could put your HTML into a separate file and just include() it
wherever you want it displayed...

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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




Re: [PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread Johannes Schlueter
On Saturday 25 January 2003 20:38, CF High wrote:

 Each operation has @ 50 lines of html -- do I have to echo or print all
 this html!?

Try something like
?php
  switch ($foo) {
case 1:
?
h1Hello/h1
?php
  break;
  }
?

johannes

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




Re: [PHP] Switch statement || How to output html without using echo()or print()

2003-01-25 Thread Leif K-Brooks
No.  You can either echo/print with a heredoc (which is still 
echoing/printing, but is a lot easier) or you can exit PHP.  For example:
?php
switch($somevar){
case 'case1':
print  END
some html
some html
some html
END;
break;
case 'case2':
print  END
some html
some html
some html
END;
break;
}
?


Or:
?php
switch($somevar){
case 'case1':
?
some html
some html
some html
?php
break;
case 'case2':
?
some html
some html
some html
?php
break;
}
?

CF High wrote:

Hey all.

Don't know if this is possible, but here goes:

I've got a simple switch statement that carries out one of several
operations based on the switch statement variable value.

Each operation has @ 50 lines of html -- do I have to echo or print all this
html!?

I'm new to PHP so pardon my ignorance here.  I'm used to the relative ease
of Cold Fusion

Thanks for any ideas/suggestions,

--Noah

--




 


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.




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




Re: [PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread Noah
That does the trick, although I'm not exactly sure why.

Shouldn't the html between the ?php case 1: ? and ?php break; }: ?
statements be executed regardless of whether or not case 1 matches the
switch variable?

In Cold Fusion anything outside of cfoutputcf code here/cfoutput is
ignored by the CF language processor; thus the ?php case 1? html here
?php break; }? would display the html for each case.

In any case thanks for workaround -- I would have echoed out all the html
otherwise..

--Noah

- Original Message -
From: Johannes Schlueter [EMAIL PROTECTED]
To: CF High [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Saturday, January 25, 2003 8:38 AM
Subject: Re: [PHP] Switch statement || How to output html without using
echo() or print()


 On Saturday 25 January 2003 20:38, CF High wrote:

  Each operation has @ 50 lines of html -- do I have to echo or print all
  this html!?

 Try something like
 ?php
   switch ($foo) {
 case 1:
 ?
 h1Hello/h1
 ?php
   break;
   }
 ?

 johannes



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




Re: [PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread Noah
Hey John.

While your suggestion certainly will work, I'd prefer not to have an
excessive number of include files to keep track of.

Johannes' suggestion does the trick:

Try something like
?php
  switch ($foo) {
case 1:
?
h1Hello/h1
?php
  break;
  }
?


- Original Message -
From: John W. Holmes [EMAIL PROTECTED]
To: 'CF High' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Saturday, January 25, 2003 8:42 AM
Subject: RE: [PHP] Switch statement || How to output html without using
echo() or print()


  I've got a simple switch statement that carries out one of several
  operations based on the switch statement variable value.
 
  Each operation has @ 50 lines of html -- do I have to echo or print
 all
  this
  html!?

 You could put your HTML into a separate file and just include() it
 wherever you want it displayed...

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/




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




Re: [PHP] Switch statement || How to output html without using echo() or print()

2003-01-25 Thread CF High
Thanks for the informative response, Leif.

Looks like you and Johannes are on the same page -- these solutions save a
great deal of time.

Thanks,

--Noah


Leif K-Brooks [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 No.  You can either echo/print with a heredoc (which is still
 echoing/printing, but is a lot easier) or you can exit PHP.  For example:
 ?php
 switch($somevar){
 case 'case1':
 print  END
 some html
 some html
 some html
 END;
 break;
 case 'case2':
 print  END
 some html
 some html
 some html
 END;
 break;
 }
 ?


 Or:
 ?php
 switch($somevar){
 case 'case1':
 ?
 some html
 some html
 some html
 ?php
 break;
 case 'case2':
 ?
 some html
 some html
 some html
 ?php
 break;
 }
 ?

 CF High wrote:

 Hey all.
 
 Don't know if this is possible, but here goes:
 
 I've got a simple switch statement that carries out one of several
 operations based on the switch statement variable value.
 
 Each operation has @ 50 lines of html -- do I have to echo or print all
this
 html!?
 
 I'm new to PHP so pardon my ignorance here.  I'm used to the relative
ease
 of Cold Fusion
 
 Thanks for any ideas/suggestions,
 
 --Noah
 
 --
 
 
 
 
 
 

 --
 The above message is encrypted with double rot13 encoding.  Any
unauthorized attempt to decrypt it will be prosecuted to the full extent of
the law.






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




[PHP] switch statement question

2002-08-13 Thread Alexander Ross

Say i have a variable $string_var = Once upon a time;

is there a way to do this:

Switch($string_var)
{
  case(contains Once):
   doSomething();
   break;
  case(contains the end.)
   doOtherThing();
   break;
  case(contains time)
   doNothing();
   break;
  default:
echo ERROR
}

Thanks
Alex




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




RE: [PHP] switch statement question

2002-08-13 Thread Jay Blanchard

[snip]
Say i have a variable $string_var = Once upon a time;

is there a way to do this:

Switch($string_var)
{
  case(contains Once):
   doSomething();
   break;
  case(contains the end.)
   doOtherThing();
   break;
  case(contains time)
   doNothing();
   break;
  default:
echo ERROR
}
[/snip]

http://www.php.net/manual/en/control-structures.switch.php

Yes Virginia, there is a PHP function :^]. You can explode your $string_var
into an array, loop through the array and test each word for a match.

HTH!

Jay



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




Re: [PHP] switch statement question

2002-08-13 Thread DL Neil

Alternatively Alexander,
take a look at the string functions eg strstr(), stristr(), and strpos() all
of which can be used to make a condition within the case() criteria.
Regards,
=dn


 [snip]
 Say i have a variable $string_var = Once upon a time;

 is there a way to do this:

 Switch($string_var)
 {
   case(contains Once):
doSomething();
break;
   case(contains the end.)
doOtherThing();
break;
   case(contains time)
doNothing();
break;
   default:
 echo ERROR
 }
 [/snip]

 http://www.php.net/manual/en/control-structures.switch.php

 Yes Virginia, there is a PHP function :^]. You can explode your
$string_var
 into an array, loop through the array and test each word for a match.

 HTH!

 Jay



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




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




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-29 Thread Christian Reiniger

On Sunday 28 October 2001 22:17, Imar de Vries wrote:
 Hi all,

 a very frustrating problem. For some reason I am not able to pass on an
 array between two functions, although I declare it global in both of
 them. I suspect my use of a switch statement to control the flow of the

[...]

 switch ($action) {
  default:
  main();
  break;
  case test_one:
  test_one();
  break;
 }

[...]

  print (pform method=\post\ action=\arraytest.php\
 enctype=\multipart/form-data\);
  ?
  input type=hidden name=action value=test_one
  input type=submit value=Test tabindex=6
  /form
  ?
 }


So you want to share the array across *requests*
That doesn't have *anything* to do with global.

Have a look at how HTTP works - each request is an isolated execution of 
a PHP script. it doesn't have any idea of what other pages the user 
already looked at. To archieve your stuff you need session management 
(phpbuilder.com has a nice tutorial on this)

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

This is JohnC IMHO, I compaired tri-word groupings here and in his plan
and got a good match.

- /. posting discussing the likelihood that an AC post that claimed to be
posted by John Carmack during his honeymoon (and having the login info at
home) was actually from him.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-29 Thread Imar de Vries

Christian Reiniger wrote:

 So you want to share the array across *requests*
 That doesn't have *anything* to do with global.

 Have a look at how HTTP works - each request is an isolated execution of
 a PHP script. it doesn't have any idea of what other pages the user
 already looked at. To archieve your stuff you need session management
 (phpbuilder.com has a nice tutorial on this)

Indeed, this is something I only came to know yesterday when Henrik replied
with an answer along the same line: every new instance of the script is
isolated from earlier instances, and therefore does not recognize the array.
I was confused though, because I thought it could be done as I succesfully
transferred other variables. Turned out all those variables were transported
inside a FORM, which does get recognized across multiple instances of the
script.

I'll have a look at documents on session management, thanks for the advice!
--
Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread Imar de Vries

Hi all,

a very frustrating problem. For some reason I am not able to pass on an
array between two functions, although I declare it global in both of
them. I suspect my use of a switch statement to control the flow of the
functions is causing some trouble, but I'm not sure. Changing the order
in which I declare the array global did not help, nor the use of
$GLOBALS.

This is a simple representation of what I do:

switch ($action) {
 default:
 main();
 break;
 case test_one:
 test_one();
 break;
}

// ---

function main() {

 $array_test = array();
 global $array_test;

 $array_test[0] = First array, first element;
 $array_test[1] = First array, second element;

 print(Content of first array in the main function is now:br);
 var_dump($array_test);

 print (pform method=\post\ action=\arraytest.php\
enctype=\multipart/form-data\);
 ?
 input type=hidden name=action value=test_one
 input type=submit value=Test tabindex=6
 /form
 ?
}

// ---

function test_one() {

 global $array_test;

// This results in NULL

 print(Content of first array in the first test function is now:br);

 var_dump($array_test);

 $array_test[2] = First array, third element;
 $array_test[3] = First array, fourth element;

// This results in the third and fourth element being shown

 print(pAfter addition, content of first array is:br);
 var_dump($array_test);
}

--
Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread Henrik Hudson

Hey-

I would think you would need to define $array_test outside in a global 
environment rather then inside the function since I think/thought it will 
just stay scoped in there and that  global was used to access variables 
which weren't defined inside a functions scope and make it look outside.

In other words

//Define GLOBAL
$array_test = array();

switch(){
BLAH
BLAH

}

function main() {
global $array_test;
BLAH
BLAH

}

function test_one(){
global $array_test;
BLAH
BLAH

}


Hope that helps.

Henrik

On Sunday 28 October 2001 15:17, Imar de Vries wrote:
  Hi all,

  a very frustrating problem. For some reason I am not able to pass on an
  array between two functions, although I declare it global in both of
  them. I suspect my use of a switch statement to control the flow of the
  functions is causing some trouble, but I'm not sure. Changing the order
  in which I declare the array global did not help, nor the use of
  $GLOBALS.

  This is a simple representation of what I do:

  switch ($action) {
   default:
   main();
   break;
   case test_one:
   test_one();
   break;
  }

  // ---

  function main() {

   $array_test = array();
   global $array_test;

   $array_test[0] = First array, first element;
   $array_test[1] = First array, second element;

   print(Content of first array in the main function is now:br);
   var_dump($array_test);

   print (pform method=\post\ action=\arraytest.php\
  enctype=\multipart/form-data\);
   ?
   input type=hidden name=action value=test_one
   input type=submit value=Test tabindex=6
   /form
   ?
  }

  // ---

  function test_one() {

   global $array_test;

  // This results in NULL

   print(Content of first array in the first test function is now:br);

   var_dump($array_test);

   $array_test[2] = First array, third element;
   $array_test[3] = First array, fourth element;

  // This results in the third and fourth element being shown

   print(pAfter addition, content of first array is:br);
   var_dump($array_test);
  }

-- 

Henrik Hudson
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread Imar de Vries

Henrik Hudson wrote:

 I would think you would need to define $array_test outside in a global
 environment rather then inside the function since I think/thought it will
 just stay scoped in there and that  global was used to access variables
 which weren't defined inside a functions scope and make it look outside.

 In other words

 //Define GLOBAL
 $array_test = array();

 switch(){
 BLAH
 BLAH

 }

 function main() {
 global $array_test;
 BLAH
 BLAH

 }

 function test_one(){
 global $array_test;
 BLAH
 BLAH

 }

Yes, the only way I could avoid errors that occurred when I tried to manipulate
the array, was to add a $array_test = array(); a few lines before the switch
statement. Alas, this also emptied the array each time I went from one function
to another via the switch statement.

I guess I am trying something that is just not possible (when I insist on using
the switch statement)?
--
Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread Henrik Hudson

Well, the switch statement will only run ONE of the functions, never both. 
The default runs and then you break out of the switch, also: shouldn't 
default be at the bottom of the switch? or is that just convention? Anyways, 
there is no way for main() to ever pass anything to test_one(), since only 
one or the other is called in the switch (unless your switch is in a loop and 
$action changes in that loop).

Oh, your passing it back in via a form and then telling it to use: test_one. 
Oh, ummm, everytime you submit the code you are calling a new instance of 
the script. It will never remember variables between instances unless they 
are passed to the script via POST and hidden fields. At least as far as I 
know...but I might be missing something.

I would try and do whatever you are trying to do without resorting to a 
resubmit or just pass the variable to the function inside main: 
test_one($array_global);

Sorry I couldn't be of more help.




On Sunday 28 October 2001 15:48, you wrote:
  Hi Henrik,

   I would think you would need to define $array_test outside in a global
   environment rather then inside the function since I think/thought it
   will just stay scoped in there and that  global was used to access
   variables which weren't defined inside a functions scope and make it
   look outside.

  Yes, the only way I could avoid errors that occurred when I tried to
 manipulate the array, was to add a $array_test = array(); a few lines
 before the switch statement. Alas, this also emptied the array each time I
 went from one function to another via the switch statement.

  I guess I am trying something that is just not possible (when I insist on
 using the switch statement)?

-- 

Henrik Hudson
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread DL Neil

Imar,
The global array is being defined in the mainline, but not populated. What happens if 
you set element 0 to some
value (to take up some storage space first) and then try the switched function calls?
When you say Alas, this also emptied the array each time I went from one function to 
another via the switch
statement. do you mean that the array definition line is inside the same loop that 
causes the switch statement
to be revisited?
(it shouldn't be - put it right at the beginning of the 'mainline' and ensure that it 
is not re-executed (which
would indeed 'reset' the values))
Regards,
=dn



- Original Message -
From: Imar de Vries [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: 28 October 2001 21:49
Subject: Re: [PHP] switch-statement overrides use of global arrays?


 Henrik Hudson wrote:

  I would think you would need to define $array_test outside in a global
  environment rather then inside the function since I think/thought it will
  just stay scoped in there and that  global was used to access variables
  which weren't defined inside a functions scope and make it look outside.
 
  In other words
 
  //Define GLOBAL
  $array_test = array();
 
  switch(){
  BLAH
  BLAH
 
  }
 
  function main() {
  global $array_test;
  BLAH
  BLAH
 
  }
 
  function test_one(){
  global $array_test;
  BLAH
  BLAH
 
  }

 Yes, the only way I could avoid errors that occurred when I tried to manipulate
 the array, was to add a $array_test = array(); a few lines before the switch
 statement. Alas, this also emptied the array each time I went from one function
 to another via the switch statement.

 I guess I am trying something that is just not possible (when I insist on using
 the switch statement)?
 --
 Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch-statement overrides use of global arrays?

2001-10-28 Thread Imar de Vries

Dl Neil wrote:

 The global array is being defined in the mainline, but not populated. What happens 
if you set element 0 to some
 value (to take up some storage space first) and then try the switched function calls?

This did not produce the desired result, unfortunately. The array is filled correctly 
within the first function,
but is empty after we've passed the switch statement en route to the second function.

 When you say Alas, this also emptied the array each time I went from one function 
to another via the switch
 statement. do you mean that the array definition line is inside the same loop that 
causes the switch statement
 to be revisited?
 (it shouldn't be - put it right at the beginning of the 'mainline' and ensure that 
it is not re-executed (which
 would indeed 'reset' the values))

The array definition line was not inside the same loop as the switch, which it looked 
like of course because there
was a reset at some point, it seemed.

Henriks answer at 23:17 seems to have hit the nail in the head: each time the variable 
$action is changed (using a
FORM), this causes the switch statement to run another function, but this also creates 
a new instance of the
script, in which the variables from the older instance are not known.

I'm now working on a solution that uses the same form to pass on some data I need. A 
bit complex maybe, but I'll
leave the code cleaning for version 2.0 of my software :)
--
Imar de Vries - [EMAIL PROTECTED] - ICQ 6972439



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] switch statement

2001-02-25 Thread Peter Houchin

Does any one know where there are some tutorials for the switch statement?

Peter Houchin
Sun Rentals
[EMAIL PROTECTED]




Re: [PHP] switch statement

2001-02-25 Thread Jon Rosenberg

Here is a basic example.

switch ($option)
{

case "optiona":
statements;
statements;
break;

case "optionb":
statements;
break;

}




- Original Message -
From: "Peter Houchin" [EMAIL PROTECTED]
To: "PHP MAIL GROUP" [EMAIL PROTECTED]
Sent: Sunday, February 25, 2001 9:03 PM
Subject: [PHP] switch statement


 Does any one know where there are some tutorials for the switch statement?

 Peter Houchin
 Sun Rentals
 [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch statement

2001-02-25 Thread David Robley

On Mon, 26 Feb 2001 12:33, Peter Houchin wrote:

  Does any one know where there are some tutorials for the switch
 statement?
 
 Peter Houchin
 Sun Rentals
 [EMAIL PROTECTED]

 
Have a quick look at 
http://www.php.net/manual/en/control-structures.switch.php
which has some user notes which are possibly useful over and above the 
actual documentation.

-- 
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] switch statement

2001-02-25 Thread Peter Houchin


I'm playing aruond with the switch statement trying to get one to work for
$submit
I have 2 forms on the one page (only one displays at a time) 1 is for
creating a new record in my data base the other is for updating/changing
values from the first form should there be any. So i want it to switch
between the 2 cases
-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 26, 2001 1:34 PM
To: Peter Houchin; PHP MAIL GROUP
Subject: Re: [PHP] switch statement


On Mon, 26 Feb 2001 12:33, Peter Houchin wrote:

  Does any one know where there are some tutorials for the switch
 statement?

 Peter Houchin
 Sun Rentals
 [EMAIL PROTECTED]


Have a quick look at
http://www.php.net/manual/en/control-structures.switch.php
which has some user notes which are possibly useful over and above the
actual documentation.

--
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] switch statement

2001-02-25 Thread David Robley

On Mon, 26 Feb 2001 13:20, Peter Houchin wrote:
 I'm playing aruond with the switch statement trying to get one to work
 for $submit
 I have 2 forms on the one page (only one displays at a time) 1 is for
 creating a new record in my data base the other is for
 updating/changing values from the first form should there be any. So i
 want it to switch between the 2 cases

OK. Suppose the possible values for $submit are 'insert' and 'update'. [I 
assume those are values _you_ can assign to a submit button]

Then

switch($submit) {

case 'insert':
  // Your insert stuff here
  break; //So it doesn't fall through to the next case

case 'update:
  // Your update stuff here
  break;

case default:
  // The page has somehow been called without a value (or an
  // inappropriate value) for submit
  // Error handling or whatever here

}

Does that make it clearer? or muddier :-)

-- 
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]