I have table name 'preferences' column(key,value)
I use cache in codeigniter
look this :
$pref = $this->ci->db->get('preferences')->result();
$this->ci->cache->save('preferences', $pref, 30000);
save cache :
a:3:{s:4:"time";i:1386246188;s:3:"ttl";i:30000;s:4:"data";a:87:{i:0;O:8:"stdClass":2:{s:3:"key";s:10:"site_title";s:5:"value";s:13:"CARS Big";}i:1;O:8:"stdClass":2:{s:3:"key";s:11:"forum_title";s:5:"value";s:14:"CARS Big forum";}i:2;O:8:"stdClass":2:{s:3:"key";s:14:"forum_per_page";s:5:"value";s:2:"10";}
...
Call cache use:
$data = $this->ci->cache->get('preferences');
print_r($data);
output:
Array(
[0] => Array
(
[key] => site_title
[value] => CARS Big
)
[1] => Array
(
[key] => forum_title
[value] => CARS Big forum
)
[2] => Array
(
[key] => forum_per_page
[value] => 10
)
[3] => Array
(
[key] => forum_section_per_page
[value] => 10
)
[4] => Array
(
[key] => forum_replies_per_page
[value] => 5
)
[5] => Array
(
[key] => forum_can_add_pictures
[value] => 1
)
[6] => Array
(
[key] => forum_can_add_poll
[value] => 1
)
[7] => Array
(
[key] => forum_can_set_time_to_close
[value] => 1
)
[8] => Array
(
[key] => forum_can_set_replies_to_close
[value] => 1
)
[9] => Array
(
[key] => forum_auto_active_topics
[value] => 1
)
[10] => Array
(
[key] => market_title
[value] => market CARS Big
)
[11] => Array
(
[key] => market_per_page
[value] => 5
)
[12] => Array
(
[key] => market_section_per_page
[value] => 3
)
)
How do I make the content of the column key is the key
And the column value is the content
Like this:
$data['site_title']
I need $data['site_title'] to print : CARS Big
so as to call this function
function pref($key=NULL)
{
$data = $this->ci->cache->get('preferences');
return $data[$key];
}
**