CodeIgniter Forums
How to get value column where column in codeigniter 3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: How to get value column where column in codeigniter 3 (/showthread.php?tid=64172)



How to get value column where column in codeigniter 3 - cnttlc - 01-22-2016

I have a table like:
Code:
sysopt|sysval
......................    
site_url|http://domain.com/
site_title|My Website
......................

in mysql i use:
Code:
$query = $db->query("SELECT * FROM sysconfig");
while ($result = $db->fetch_array($query)) {
   $settings[$result['sysopt']] = $result['sysval'];
}

But in CI:
Code:
class Sysinfo
{
   var $info = array();

public function __construct()
{
   $CI =& get_instance();
   $settings = $CI->db->select("*")
   ->get("sysconfig");
   foreach($settings as $setting) {
       $this->info[$setting['sysopt']] = $setting['sysval'];
   }
}

In view i call:
Code:
<?php echo $this->Sysinfo->info->site_url; ?>

Show error.
Code:
Message: Undefined property: CI_Loader::$Sysinfo

Thankyou any solution fix.


RE: How to get value column where column in codeigniter 3 - InsiteFX - 01-23-2016

You can try this, but it is not recommended to do in a view it should be done in your controller.

PHP Code:
<?php
    $CI 
= =& get_instance();
 
   echo $CI->this->Sysinfo->info->site_url;
?>



RE: How to get value column where column in codeigniter 3 - keulu - 01-28-2016

yo

you affect your data directly to $infos array in your controller.

$this->info['site_url'] = 'http://www.google.com';

so why do you call $this->Sysinfo->info->site_url ?

call directly echo $this->info['site_url']; // will show "http://www.google.com"