shyam13 Posted August 9, 2012 Share Posted August 9, 2012 Can you use a Get Method inside a if statement and if you can, how would this be possible? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/ Share on other sites More sharing options...
Psycho Posted August 9, 2012 Share Posted August 9, 2012 Your question is so vague that it needs to be answered with a correspondingly vague response. Yes you can use a method as a condition. How you would use it would be based entirely on the possible return values of the method and what your needs are. If you are having some trouble with some code, post the relevant code and what your problem is. Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368134 Share on other sites More sharing options...
shlumph Posted August 9, 2012 Share Posted August 9, 2012 Can you use a Get Method inside a if statement and if you can, how would this be possible? Yes, a little vague. Are you thinking something like this? if($a == $b) { $data = getSomeData(); } Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368135 Share on other sites More sharing options...
shyam13 Posted August 9, 2012 Author Share Posted August 9, 2012 I have created a table where you can select insects and the insect_slug will be sent to the URL for example: www.website.com/insectscientific/acrolepiopsisassectella, when user then clicks on the product they will be redirected to another page where, if the URL slug is same to the insect slug in the database display the information for that product. Code: <?php if ($_GET['insect_slug'] === ($insect['insect_slug'])); echo $insect['insect_mdes']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368139 Share on other sites More sharing options...
shlumph Posted August 9, 2012 Share Posted August 9, 2012 You can use the $_GET variable as part of a condition, if that's what you're asking. You can use it just like any other variable. Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368142 Share on other sites More sharing options...
The Little Guy Posted August 9, 2012 Share Posted August 9, 2012 That should work, but the semi-colon should be removed. Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368143 Share on other sites More sharing options...
Psycho Posted August 9, 2012 Share Posted August 9, 2012 <?php if ($_GET['insect_slug'] === ($insect['insect_slug'])); echo $insect['insect_mdes']; ?> That is not a Get method, that is the superglobal $_GET array. Two completely different things. The reason you are probably not getting the results you expect is due to the semicolon at the end of the condition. That terminates that line. So, the next line with the echo will always execute. You should have used if ($_GET['insect_slug'] === ($insect['insect_slug'])) echo $insect['insect_mdes']; Personally, I hate that method of if/else statements I always wrap the code associated with my conditions within curly braces for readability if ($_GET['insect_slug'] === ($insect['insect_slug'])) { echo $insect['insect_mdes']; } But, there is nothing inherently wrong with your usage there. But, depending on how those values are determined and what they actually contain I can't say whether they would work for your needs. If you have a situation where values do or do not compare as you think they should then you need to verify the contents of those values. Quote Link to comment https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368145 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.