Reputation: 2331
Can you read out the name of a PHP constant from a database and use it inside of a php variable, to display the value of the constant for use in a menu?
For example here's what I'm trying to accomplish
In SQL: select menu_name AS php_CONSTANT where menu_id=1
the value returned would be L_HOME which is the name of a CONSTANT in a php config page. The php config page looks like this define('L_HOME','Home');
and gets loaded before the database call.
The php usage would be $db_returned_constant
which has a value of L_HOME
that came from the db call, then I would place this into a string such as $string = '<ul><li>' . $db_returned_constant . '</li></ul>'
and thus return a string that looks like $string = '<ul><li><a href="#" onclick="path_from_db">Home</a></li></ul>'
.
To sum up what I'm trying to do
I hope this makes enough sense...is it even possible to use a constant like this?
Thanks.
Upvotes: 1
Views: 2053
Reputation: 8279
define('L_HOME','Home');
$db_returned_constant = 'L_HOME'; // value actually retrieved from db
echo constant($db_returned_constant);
// will output 'Home'
Upvotes: 2