...

View Full Version : Switch statement



grudz
01-20-2004, 05:44 PM
Hello,

Ive been having a big problem here is the thread (http://www.codingforums.com/showthread.php?s=&threadid=31539) . So for the last 2 weeks ive been trying to figure something. I am a newbie in PHP coding, but i am willing to learn and work hard. I read that having a "Switch Statement" might help, however, i am now completly lost as to how that works, can someone help me? I was reading on php.net, but that didnt help that much, does anybody have any other ideas?

thank you very much

SDP2006
01-20-2004, 10:31 PM
Just a basic switch statement


<?php
$cat = $_GET['cat'];
switch($cat){

case "contact";
echo "Contact Us";
break;

case "join";
echo "Join our Site!";
break;

default;
echo "Welcome to our site!";
break;
}
?>

Now the cases are what to do 'in case' variable $cat equals "contact" thus case "contact"; and the same for "join." Obviously, default is what to do in case none of the cases match.

Hope this helps.

me'
01-20-2004, 10:34 PM
Typos:

case "contact";

echo "Contact Us";

break;Should be
case "contact":

echo "Contact Us";

break;

SDP2006
01-20-2004, 11:11 PM
Really?

I've never got errors with case "contact";

Thanks anyway.

Spookster
01-20-2004, 11:49 PM
Originally posted by SDP2006
Really?

I've never got errors with case "contact";

Thanks anyway.

Yes really. Your switch statement is incorrect. You should consult the PHP manual.

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

SDP2006
01-21-2004, 04:23 PM
Well, thanks for the heads up guys :)

grudz
01-21-2004, 06:58 PM
k thanx....but is the switch what i need for my problem my problem (http://www.codingforums.com/showthread.php?s=&threadid=31539) look at my last post. So would this solve my problem...

thanx again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum