Re: [PHP] Control Structure problem
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... yeah, i really like using cases they work well and especially if you want to do something different for different values, i forgot about that, its a good way to do it, does php have case else? cuz that is a really handy thing in VB that people often forget... You mean 'default' switch ($var) { case 'TEST-1': case 'TEST-2': case 'TEST-2': do_something(); break; // to stop falling through to next option default: // any other case not above do_other_thing(); break; //Not really needed as is last statement but good practice } And default can appear anywhere in the statement, not just as last item. Cheers -- Quod subigo farinam A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Control Structure problem
This doesnt work as expected. if ( $var === TEST ONE || TEST TWO || TEST THREE) { do something; } It returns true on all strings. Ive tried using the or operator and the == but these fail as well. Any Ideas? It behaves exactly as expected. Try checking the manual section on control structures, I believe it explains that the syntax you are using is invalid. What you are saying is if ( $var === (TEST ONE || TEST TWO || TEST THREE)) { (TEST ONE || TEST TWO || TEST THREE) is always going to evaluate as true. I think what you want is if ( $var === TEST ONE || $var === TEST TWO || $var === TEST THREE) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
try if ( $var == TEST ONE || $var == TEST TWO || $var == TEST THREE) { do something; } luke - Original Message - From: Dan J. Rychlik [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 9:53 AM Subject: [PHP] Control Structure problem This doesnt work as expected. if ( $var === TEST ONE || TEST TWO || TEST THREE) { do something; } It returns true on all strings. Ive tried using the or operator and the == but these fail as well. Any Ideas? -Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. Thank you again. -Dan - Original Message - From: Luke Skywalker [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, September 16, 2003 7:01 PM Subject: Re: [PHP] Control Structure problem try if ( $var == TEST ONE || $var == TEST TWO || $var == TEST THREE) { do something; } luke - Original Message - From: Dan J. Rychlik [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 9:53 AM Subject: [PHP] Control Structure problem This doesnt work as expected. if ( $var === TEST ONE || TEST TWO || TEST THREE) { do something; } It returns true on all strings. Ive tried using the or operator and the == but these fail as well. Any Ideas? -Dan -- 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] Control Structure problem
I think speaking for everyone its great to be able to help, we all started somwhere :) i remember getting stuck on the same problem in visual basic ages ago Luke - Original Message - From: Dan J. Rychlik [EMAIL PROTECTED] To: Luke Skywalker [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:12 AM Subject: Re: [PHP] Control Structure problem Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. Thank you again. -Dan - Original Message - From: Luke Skywalker [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, September 16, 2003 7:01 PM Subject: Re: [PHP] Control Structure problem try if ( $var == TEST ONE || $var == TEST TWO || $var == TEST THREE) { do something; } luke - Original Message - From: Dan J. Rychlik [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 9:53 AM Subject: [PHP] Control Structure problem This doesnt work as expected. if ( $var === TEST ONE || TEST TWO || TEST THREE) { do something; } It returns true on all strings. Ive tried using the or operator and the == but these fail as well. Any Ideas? -Dan -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Control Structure problem
Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. lovingjab If by I truly know the level of expertise on this mailing list you meant I truly don't know the basics of PHP syntax, then yeah, you'd be right. ;) !! /lovingjab :) Chris. p.s. Or maybe it's me that's doesn't know the basics... ?? p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
yeah, it does make more sense to do it that way for some things, but when you get ands, and ors, it gets complicated eg. if ($a == foo $b == bar || something){ //do something } does that mean $a can either = foo or something or $b = bar or something? and thats just a simple example :) but i know it would be really nice in simple logical expressions Luke - Original Message - From: Chris W. Parker [EMAIL PROTECTED] To: Dan J. Rychlik [EMAIL PROTECTED]; Luke Skywalker [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:18 AM Subject: RE: [PHP] Control Structure problem Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. lovingjab If by I truly know the level of expertise on this mailing list you meant I truly don't know the basics of PHP syntax, then yeah, you'd be right. ;) !! /lovingjab :) Chris. p.s. Or maybe it's me that's doesn't know the basics... ?? p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... -- 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] Control Structure problem
* Thus wrote Chris W. Parker ([EMAIL PROTECTED]): Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... Well technically you can do it like: switch ($var) { case 'TEST-1': case 'TEST-2': case 'TEST-2': do something } Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
yeah, i really like using cases they work well and especially if you want to do something different for different values, i forgot about that, its a good way to do it, does php have case else? cuz that is a really handy thing in VB that people often forget... Luke - Original Message - From: Curt Zirzow [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:49 AM Subject: Re: [PHP] Control Structure problem * Thus wrote Chris W. Parker ([EMAIL PROTECTED]): Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... Well technically you can do it like: switch ($var) { case 'TEST-1': case 'TEST-2': case 'TEST-2': do something } Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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] Control Structure problem
are you thinking of default: ? -Original Message- From: Luke Skywalker [mailto:[EMAIL PROTECTED] Sent: Wednesday, 17 September 2003 10:51 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Control Structure problem yeah, i really like using cases they work well and especially if you want to do something different for different values, i forgot about that, its a good way to do it, does php have case else? cuz that is a really handy thing in VB that people often forget... Luke - Original Message - From: Curt Zirzow [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:49 AM Subject: Re: [PHP] Control Structure problem * Thus wrote Chris W. Parker ([EMAIL PROTECTED]): Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... Well technically you can do it like: switch ($var) { case 'TEST-1': case 'TEST-2': case 'TEST-2': do something } Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
Yeah, thats exactly what im thinking, and speaking of it, im going to start using it a lot more :) thanks Luke - Original Message - From: Martin Towell [EMAIL PROTECTED] To: 'Luke Skywalker' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:51 AM Subject: RE: [PHP] Control Structure problem are you thinking of default: ? -Original Message- From: Luke Skywalker [mailto:[EMAIL PROTECTED] Sent: Wednesday, 17 September 2003 10:51 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Control Structure problem yeah, i really like using cases they work well and especially if you want to do something different for different values, i forgot about that, its a good way to do it, does php have case else? cuz that is a really handy thing in VB that people often forget... Luke - Original Message - From: Curt Zirzow [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 10:49 AM Subject: Re: [PHP] Control Structure problem * Thus wrote Chris W. Parker ([EMAIL PROTECTED]): Dan J. Rychlik mailto:[EMAIL PROTECTED] on Tuesday, September 16, 2003 5:12 PM said: Thank you guys. I truly know the level of expertise on this mailing list, and I know that it proves invaluable. p.p.s. I totally think that the syntax you presented is logical and should be available. It makes much more sense to me to do it the way you did, but alas... Well technically you can do it like: switch ($var) { case 'TEST-1': case 'TEST-2': case 'TEST-2': do something } Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
On Wed, Sep 17, 2003 at 12:49:03AM +, Curt Zirzow wrote: : : switch ($var) { : case 'TEST-1': case 'TEST-2': case 'TEST-2': : do something : } The switch statement doesn't do an equivalency test, does it? So while this switch statement can be rewritten as: if (($var == 'TEST-1') || ($var == 'TEST-1') || ($var == 'TEST-1')) { do something } it doesn't do: if (($var === 'TEST-1') || ($var === 'TEST-1') || ($var === 'TEST-1')) { do something } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
* Thus wrote Eugene Lee ([EMAIL PROTECTED]): On Wed, Sep 17, 2003 at 12:49:03AM +, Curt Zirzow wrote: The switch statement doesn't do an equivalency test, does it? So while this switch statement can be rewritten as: if (($var == 'TEST-1') || ($var == 'TEST-1') || ($var == 'TEST-1')) { do something } it doesn't do: if (($var === 'TEST-1') || ($var === 'TEST-1') || ($var === 'TEST-1')) { do something } Correct. Although in most cases == is a good enough test. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
On Wed, Sep 17, 2003 at 01:29:26PM +1000, Tom Rogers wrote: : Wednesday, September 17, 2003, 11:47:45 AM, Eugene Lee wrote: : : EL The switch statement doesn't do an equivalency test, does it? [...] : EL it doesn't do: : : EL if (($var === 'TEST-1') || : EL($var === 'TEST-1') || : EL($var === 'TEST-1')) : EL { : EL do something : EL } : : You can do it this way I think :) : : switch (true) { : case ($var === 'TEST-1')?true:false: : case ($var === 'TEST-2')?true:false: : case ($var === 'TEST-2')?true:false: :do something : } Oh man, that's just sick... I guess, for the sake of performance and readability, it's probably easier to do an is_string($var) (or whatever variable type) before doing a normal switch statement. Still... that's just sick... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control Structure problem
--- Eugene Lee [EMAIL PROTECTED] wrote: : switch (true) { : case ($var === 'TEST-1')?true:false: : case ($var === 'TEST-2')?true:false: : case ($var === 'TEST-2')?true:false: :do something : } Oh man, that's just sick... Partially because it's unnecessarily complex. This is like saying: if ($var === 'TEST-1') { $expression = true; } else { $expression = false; } if ($expression) { ... While the ternary operator makes this redundancy less obvious, it only adds to the complexity and lack of readability. Consider the following code as a substitute for the above example: if ($var === 'TEST-1') { ... Hopefully that part is clear. Now, on to the original question. Try this example: ? $foo = 'bar'; switch (true) { case ($foo === 'notbar'): echo 'A'; break; case ($foo === 'bar'); echo 'B'; break; default: echo 'C'; break; } ? This should output B. You will also notice that it works when you switch on $foo instead of the boolean true, but this is misleading. PHP converts $foo to the boolean true when comparing to the expressions, because we set it to the string bar. To understand this point further, try this example: ? $foo = 0; switch ($foo) { case ($foo === 'notbar'): echo 'A'; break; case ($foo === 0); echo 'B'; break; default: echo 'C'; break; } ? This should also output B. That seems to be wrong, but in this case it is comparing each expression to $foo, which is the integer 0 in this case, so it evaluates to false. So, you will see A, because ($foo === 'notbar') also evaluates to false. Recap: 1. You can switch on anything, including boolean values. 2. Your cases can be expressions to be evaluated. Hope that helps. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Control Structure Problem
I forgot to say I deleted tabs so that the width might fit in a typical mail reader. Jeff Oien This code assigns rooms to kids signing up for Sunday school at a very large church. Each subsequent registration is put into the next room on the list. It looks up in the MySQL database the room the last person in that age category and hour was assigned and assigns the current person the next one. If someone is the first person they get assigned the first room. However if they are the first person ${newroom.$x} doesn't get assigned to anything. But thereafter it works fine. I've had a couple other problems and am wondering if there is a better way to do this or if I have any syntax problems. Thanks. Jeff Oien $x = 1; while ($x = $Number_Children) { if (${category.$x} == 'SS KidZone - Kindergarten') { if ((${Grade.$x}) == 'K' (${selection.$x}) == '2nd Hour') { $sql = SELECT * FROM $table_name WHERE Category = 'SS KidZone - Kindergarten' Element1 = '2nd Hour' ORDER by ID desc; $result = @mysql_query($sql,$connection) or die(Couldn't execute query); if ($row = mysql_fetch_array($result)) { $room = $row['Element2']; if ($room == 'C143 Pink Check') { ${newroom.$x} = 'C143 Pink Dot'; } if ($room == 'C143 Pink Dot') { ${newroom.$x} = 'C148 Teal Check'; } if ($room == 'C148 Teal Check') { ${newroom.$x} = 'C148 Teal Dot'; } if ($room == 'C148 Teal Dot') { ${newroom.$x} = 'C143 Pink Check'; } } else { ${newroom.$x} = 'C143 Pink Check'; } } do database insertion } $x++; } -- 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]