how to get bank value in an if using php

Asked

Viewed 941 times

0

people i have a table user who has a category field that is a field Boolean, at a certain point in my code I need that only if category is true I show an option in my menu, but do not know how to put no if, someone can help me, I’m trying like this but it’s not working:

<?php if((['usuario']['categoria']) == "true") {?>
<li id="users">


</li>
<?php }?>
  • 2

    Ta missing a variable ai ['usuario']['categoria'] can be an array ... if you want to compare a boolean you can also simplify.

  • 1

    It would not be the same question as this https://answall.com/questions/200779/comond-blockingfeatures-depending on the user?

  • I put a variable, but now I think if it’s not right because it’s working but even qnd category is false it ta considering true kk has something wrong

  • Do var_dump of your variable and post here the result, please.

  • ta returning NULL ...

  • So your variable is wrong. How are you setting it?

  • This column is int or varchar on the seat?

  • then I created the variable.. ta so now if.... <? php if(($Register user['users']['category'])) {?>

  • i set the variable so $this->set('Register user');

  • i n am able to pass the value of the category field to the variable

Show 5 more comments

2 answers

1

The way the if is the comparison is made between an empty array and a boolean one that "true" is converted not because of the true in yes but because of the existence of some content. An interesting example:

var_dump(false == "false"); //false.

To solve your problem, the first step is to add the variable in the comparison. The second is to simplify the comparison PHP cast (for boolean) values all the time so to know if any value is true just play it in if or expression.

Change:

<?php if((['usuario']['categoria']) == "true") {?>

For something like:

<?php if($registro['usuario']['categoria']) {?>
  • so I did it now friend, I think my problem is now in passing the value of the field to the variable, <?php if(($Register user['users']['category'])) {?>

  • declare the variable so $this->set('Register user'); ... axo qe n am able to pass the value of the category field to the variable

0

If I understand correctly, you can do it like this:

    $sql = mysql_query("SELECT categoria FROM usuario WHERE id = 'meuUser'");
    $result = mysql_fetch_assoc($sql);

    if ($result["categoria"] == "true"){

        echo "<li id='users'>

        </li>";
    }
  • 2

    The functions mysql_* are obsolete since version 5.5 of PHP and have been entirely removed from PHP 7, so it is not recommended to use them currently. Use mysqli_* in place or PDO.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.