php - Database array into single user defined variables -


im trying setup dynamic settings database cms

database set 2 columns.

name | value  template | exige  installfolder | v2 

basically want pull data out , put different variables.

for example i'm trying set base_folder(installation folder) variable.

so $base_folder = $coresettings[1] output should show (v2)

$sql = "select * core_settings"; $query = mysqli_query($dbc, $sql) or die (mysqli_error($dbc));  $coresettings = array();  while($row = mysqli_fetch_assoc($query)){    // add each row returned array    $coresettings[] = $row;    }   $base_folder = $coresettings;   foreach( $coresettings $key => $val)    { $$key = $val; }  var_dump($base_folder); 

this outputs:

array(5) { [0]=> array(2) { ["name"]=> string(8) "template" ["value"]=> string(5) "exige" } [1]=> array(2) { ["name"]=> string(13) "installfolder" ["value"]=> string(2) "v2" } [2]=> array(2) { ["name"]=> string(16) "maintainancemode" ["value"]=> string(1) "0" } [3]=> array(2) { ["name"]=> string(4) "logo" ["value"]=> string(8) "logo.png" } [4]=> array(2) { ["name"]=> string(8) "sitename" ["value"]=> string(18) "black nova designs" } }  

i installfolder value.

so

$base_folder = v2 

sorry if comes across stupid racked brain about, , code quite messed due trying multiple methods.

but in long run every setting out of database , able assign variable each setting.

for example

$sitename = $coresettings[4]; $maintenance = $coresettings[2]; 

thanks in advanced. kyle

index $coresettings array values of 1st column, can access values appropriate key:

$coresettings = array();  while($row = mysqli_fetch_assoc($query)){     // add each row returned array    $coresettings[$row['name']] = $row['value'];   }  echo $coresettings['installfolder']; //outputs v2 echo $coresettings['template']; //outputs exige 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -