php - website setting in a database table -
i building cms,
the cms info stored in mysql
database
within table
called cms_settings
i want setting_value
, store variable, example:
$cms_url = ?; $cms_theme = ?;
i've tried utilize mysqli_fetch_array()
couldn't create right.
<?php require('db.php'); $s = mysqli_query($conn, "select * cms_settings"); $i = mysqli_fetch_array($s); foreach($i $key=>$value) { $cms_url = $i[0][2]; } ?>
but didn't work!
your help highly appreciated,
you need loop through results. maybe seek this:
<?php require('db.php'); $settings = array(); $s = mysqli_query($conn, "select * cms_settings"); while($row = mysqli_fetch_assoc($s)) { $settings[$row['setting_name']] = $row['setting_value']; }
edit: added saving settings array.
edit2: if want specific settings, maybe set in function.
function getsetting($name) { require('db.php'); $name = mysqli_real_escape_string($conn, $name); $s = mysqli_query($conn, "select * cms_settings `setting_name` = '{$name}'"); while($row = mysqli_fetch_assoc($s)) { homecoming $row['setting_value']; } homecoming false; }
php mysql foreach
No comments:
Post a Comment