last day (14 days later) » 

1:55 PM
0
A: website setting in a database table

Bas SlatsYou need to loop through your results. Maybe try something like this: <?php require('db.php'); $settings = array(); $s = mysqli_query($conn, "SELECT * FROM cms_settings"); while($row = mysqli_fetch_assoc($s)) { $settings[$row['setting_name']] = $row['setting_value']; } edit: added sav...

 
Thanks, BUT I am getting the following error: Parse error: syntax error, unexpected 'array' (T_ARRAY) in...
 
woops, no new keyword in front of array!
 
Great, this will output all the rows, but how can I grap a specific setting value? like the cms_url value and save it to $cms_url variable by using the row index.
 
If you want a specific setting probably the easiest thing to do is to change your query to: $s = mysqli_query($conn, "SELECT * FROM cms_settings WHERE setting_name = 'cms_url'"); This will only return the specific row.
 
Yes, this will work but if I have a 100 settings then I have to have a 100 query!
 
1:55 PM
see my edit, you can create a function for this purpose :)
hi
 
Hi,
I've updated the code, and I called the function echo getSetting('cms_url'); but I got this notice: Notice: Array to string conversion in
 
ok, it's returning an array now
so when you want to echo it, it breaks
if you would use print_r(getSetting('cms_url')) it would work, but it's not the function you want :)
I will make an edit to the code to just return the string
 
great
 
changed it, try that :)
 
Works like a charm :))
Voted up and accepted :)
 
2:01 PM
awesome :)
 
Thanks a lot Bas
 
Good luck with your CMS Sultan!
 
Thanks,
have a nice time...
 

last day (14 days later) »