[eluser]Steeep[/eluser]
Well for starters, excuse my bad English, not my native language.
I have the following code, but I get problems when displaying results database & save them to a file.
Code:
$mode = !file_exists(APPPATH . 'config/forum.php') ? 'x' : 'w';
$options = array(
"order_by" => "stid",
"order_dir" => "ASC"
);
$query = $this->db->query('SELECT title, value FROM settings ORDER BY ' .$options['order_by']. ' ' .$options['order_dir']);
foreach ($query->result_array() as $setting)
{
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings = "\$config['forum']['{$setting['title']}'] = \"{$setting['value']}\";\n";
print_r($settings);
}
$settings = "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); \n\n/* \n| -------------------------------------------------------------------\n| FORUM SETTINGS\n| -------------------------------------------------------------------\n| This file contains personal settings of your forum. These data are generated by the database.\n|\n*/\n\n$settings\n?".">";
$file = @fopen(APPPATH . "config/forum.php", $mode);
@fwrite($file, $settings);
@fclose($file);
It should show the results as follows:
Code:
$config['forum']['closed'] = "1";
$config['forum']['closed_reason'] = "";
$config['forum']['name'] = "ForumCI";
$config['forum']['url'] = "";
$config['forum']['friendly_urls'] = "0";
Pero solo me muestra & guarda solo el último resultado, así:
Code:
$config['forum']['friendly_urls'] = "0";
And if I change the foreach for while, I get errors & saves me the results correctly. The code is this:
Code:
if(!file_exists("config/forum.php"))
{
$mode = "x";
}
else
{
$mode = "w";
}
$options = array(
"order_by" => "stid",
"order_dir" => "ASC"
);
$query = $db->query('SELECT title, value FROM settings ORDER BY ' .$options['order_by']. ' ' .$options['order_dir']);
while($setting = $db->fetch_array($query))
{
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings = "\$config['forum']['{$setting['title']}'] = \"{$setting['value']}\";\n";
}
$settings = "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); \n\n/* \n| -------------------------------------------------------------------\n| FORUM SETTINGS\n| -------------------------------------------------------------------\n| This file contains personal settings of your forum. These data are generated by the database.\n|\n*/\n\n$settings\n?".">";
$file = @fopen("config/forum.php", $mode);
@fwrite($file, $settings);
@fclose($file);
I can do?