FUNKAM35 Posted June 26, 2008 Share Posted June 26, 2008 switch ($animal){ case "cat": echo" dog"; break; Instead of ECHO and it displaying both how do I get it to only display dog? Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/ Share on other sites More sharing options...
ratcateme Posted June 26, 2008 Share Posted June 26, 2008 what do you mean by "both"?? what is the output you get. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574943 Share on other sites More sharing options...
FUNKAM35 Posted June 26, 2008 Author Share Posted June 26, 2008 At moment get cat dog I only want it to show dog so dont want it to echo but to replace Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574948 Share on other sites More sharing options...
ratcateme Posted June 26, 2008 Share Posted June 26, 2008 i dont really understand what you are saying but i think u want switch ($animal){ case "cat": $animal = "dog"; break; try posting your hole code Scott. Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574952 Share on other sites More sharing options...
FUNKAM35 Posted June 26, 2008 Author Share Posted June 26, 2008 I don't want it to echo I want it to display dog instead of cat but at the moment it is displaying both cat dog I tried what u said and it doesnt work.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574960 Share on other sites More sharing options...
trq Posted June 26, 2008 Share Posted June 26, 2008 Post your actual code! Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574972 Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 I suggest you read some documentation in understanding a switch statement. A switch statement is just an alternative to an else if block. Read here: http://uk2.php.net/manual/en/control-structures.switch.php Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-574974 Share on other sites More sharing options...
kenrbnsn Posted June 26, 2008 Share Posted June 26, 2008 Is this a continuation of your previous question? If so you should have just added another question to that thread. Ken Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-575011 Share on other sites More sharing options...
FUNKAM35 Posted June 26, 2008 Author Share Posted June 26, 2008 This is a continuation, someone has suggested I use str replace so how do I change $animal cat to dog and if I want to alter multiple fields? Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-575075 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 Post your entire code... Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-575112 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 From your other post, and confusing explanations i can only work out the following: this code: echo "<a href=\"animals.php?animal=$animal\">$animal</a>"; switch($animal){ case "cat": print 'Dog'; break; case "Pig": print 'Test'; break; } looka like this? CatDog The only way you can get around this is by... switch($_GET['animals']){ case 'Cat': $animal ='Dog'; break; case 'Pig': $animal ='Test'; break; } print "<a href=\"animals.php?animal=$animal\">$animal</a>"; If Animal is Cat, will return: Dog Quote Link to comment https://forums.phpfreaks.com/topic/112010-switch-query/#findComment-575116 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.