Reputation: 9293
I have a table vars
containing variables only. There are three columns:
id
- id
name
- variable name
val
- variable value
I need to declare that variables and give them corresponding values, something like:
$stmt = $db->query("SELECT * FROM vars order by id asc");
while($row = $stmt->fetch()){
'$' . $row['name'] = "'" . $row['val'] . "'";
}
echo $somevariable...
Any help?
Upvotes: 0
Views: 37
Reputation: 395
$stmt = $db->query("SELECT * FROM vars order by id asc");
while($row = $stmt->fetch()){
${$row['name']} = $row['val'];
}
Try this However you need to make sure that $row['name'] is compliant with PHP variable naming requirements
Upvotes: 1
Reputation: 11171
I think you want to do something like this
$$row['name'] = $row['val'];
Upvotes: -1