how to get value from the bank in an if using php

0

people I have a user table that has a category field that is a boolean field, at some point in my code I need only if category is true I show an option in my menu but I do not know how to put this in the if, somebody can help me, I'm trying like this but it's not working:

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


</li>
<?php }?>
    
asked by anonymous 26.04.2017 / 19:44

2 answers

0

If I understand correctly, you can do 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>";
    }
    
26.04.2017 / 22:12
0

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 does cast (for Boolean) values all the time so to know if any value is "true just play it in if or in the expression.

Change:

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

For something like:

<?php if($registro['usuario']['categoria']) {?>
    
26.04.2017 / 22:23