mrjimoy_05
mrjimoy_05

Reputation: 3568

Define constant through looping

I try to define constant value through looping, but it got error:

Notice: Use of undefined constant XXXXX - assumed 'XXXXX' in XX on line XX

This is the code:

$q = "SELECT `Key`, `Value` FROM appconfig";
//I skip the line to read from database
while($fetch = mysqli_fetch_array($r)) {
    define("'" . $fetch["Key"] . "'", $fetch["Value"]);
    //I try to echo $fetch["Key"] and $fetch["Value"] and it returns value
}

Something wrong with the code? I tried to define it manually and it works.

Upvotes: 1

Views: 48

Answers (1)

nickb
nickb

Reputation: 59699

Don't use the quotes, you don't need them:

define($fetch["Key"], $fetch["Value"]);

Upvotes: 3

Related Questions