My config table:
name | value
--------+------
version | 1.5.6
title | test
How I try and get it:
$getCfg = mysql_query("SELECT * FROM config");
$config = mysql_fetch_assoc($getCfg);
echo $config['title'];
Equals to:
Notice: Undefined index: title in C:\web\index.php on line 5
How would I get the value where the name is title?
The above doesn't work..well if I add WHERE title = 'test' and then echo $config['title']
Try this instead:
echo $config['name'];
You need to index the result of mysql_fetch_assoc
with the field name from the database which is "name".
$getCfg = mysql_query("SELECT * FROM config");
$config = array();
while ($row = mysql_fetch_assoc($getCfg)) {
$config[$row['name']] = $row['value'];
}
echo $config['title'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With