Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368134
Share on other sites

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'];

?>

Link to comment
https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368139
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/266866-get-function/#findComment-1368145
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.