swampone Posted July 3, 2010 Share Posted July 3, 2010 i have a form that is a search field. When submitted it goes through a switch case statement. And if certain search words are entered a url for that case should be returned, but instead its using the default case url for every word entered in the search field. For example if a user enters amateur in the search field it goes to the default case. I know that the $searchTerm is making it through all the cases, because if you look at the default case it has $searchTerm in the url, and once form is submitted I can see the searchTerm in the url and the script is working properly. But it seems like its not stopping once it has a match with one of the cases. if (isset($_GET['search'])){ $searchTerm = isset($_GET['search']); switch ($searhTerm){ case "": $url = "http://www.pornhub.com/video?o=mr&page=$page"; break; case "amateur": $url = "http://www.pornhub.com/video?c=3&page=$page"; break; case "anal": $url = "http://www.pornhub.com/video?c=35&page=$page"; break; default: $url = "http://www.pornhub.com/video/search?search=$searchTerm&x=0&y=0&page=$page"; break; } } Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/ Share on other sites More sharing options...
Pikachu2000 Posted July 3, 2010 Share Posted July 3, 2010 It appears you've misspelled something here . . . switch ($searhTerm) Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080713 Share on other sites More sharing options...
swampone Posted July 3, 2010 Author Share Posted July 3, 2010 Thanks, great find, but now it stoping at the amateur case for every word entered. Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080717 Share on other sites More sharing options...
Alex Posted July 3, 2010 Share Posted July 3, 2010 The way you have it $searchTerm will either be true or false, whatever isset returns. I think you want something like this: $searchTerm = isset($_GET['search']) ? $_GET['search'] : ''; Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080720 Share on other sites More sharing options...
kenrbnsn Posted July 3, 2010 Share Posted July 3, 2010 Replace these two lines <?php $searchTerm = isset($_GET['search']); switch ($searhTerm){ ?> with <?php switch ($_GET['search']) { ?> You've already determined that it's set, so just use it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080724 Share on other sites More sharing options...
swampone Posted July 3, 2010 Author Share Posted July 3, 2010 Wow!! That worked. You saved me so much time. I probably would been at it for hours trying to figure this out. After your explaination, I see what you are saying about anything entered returned true, but how you came up with ? $_GET['search'] : '' Wow! I still have a lot to learn. Thanks a bunch. Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080728 Share on other sites More sharing options...
Alex Posted July 3, 2010 Share Posted July 3, 2010 I didn't realize that you were already checking to see if the variable was set, so kenrbnsn's solution is more fitting. The code you're asking about is the ternary operator. Quote Link to comment https://forums.phpfreaks.com/topic/206637-isset-and-switch-case/#findComment-1080744 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.