1
I have the following code in a PHP file :
<?php if($debug == 1){ ?>
<button id="btn-debug" class="btn btn-default"><i class="fa fa-bug"></i></button>
<?php } ?>
The variable debug
is called here in another file:
$debug = data_setting_value($dbc, 'debug-status');
The function data_setting_value
is contained in another file, this function fetches a table in the database for the field value value
, which in this case is 1
function data_setting_value($dbc, $id){
$q = "SELECT * FROM settings WHERE id = '$id'";
$r = mysqli_query($dbc, $q);
$data = mysqli_fetch_assoc($r);
return $data['value'];
}
The problem is that the button is not showing me on the page, and you should see that the value field in the database is 1
And how do files relate to each other? All are included in the same file?
– Woss
Yes, I have several functions among the files, that’s not the problem, what I noticed is that the function is not returning any value
– Rafael Duarte
can try a
print_r($debug)
before the if and inspect what content the variable is receiving? another question: this column of the bankvalue
is not a string? if yes, the condition would beif($debug == "1")
– mrlew
The point is, for the code to work, the three parts must be running in the same context. The second file should include the third, so that the function
data_setting_value
exist in your symbol table. The same happens in the first file, which must include the second so that$debug
exist in its context. Or the three files being included , in the order of precedence, in a fourth file. You are doing something like this?– Woss
In the index.php file I have included the setup.php file and navigation.php. In setup.php I have included the file that has the function, and in the navigation file I have the if statement
– Rafael Duarte