2

I am trying to retrieve the config_value on the basis of config_name from the table as shown in image in codeigniter project. Even i am not able to understand where to start.I find something like this on internet (for Sample).

$this->db->select('age');
$this->db->where('id', '3');
$q = $this->db->get('my_users_table');
$data = $q->result_array();

echo($data[0]['age']);

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ajay Singh
  • 69
  • 1
  • 10

4 Answers4

3

Do something like this :

$this->db->where('config_name', 'Account_activation');
$q = $this->db->get('my_users_table');
/* if u r fetching one row use row_array instead of result_array*/
$row = $q->row_array();

echo $row['config_value'];

For more : https://www.codeigniter.com/user_guide/database/index.html

Pradeep
  • 9,667
  • 13
  • 27
  • 34
0

If you want to retrieve config value on the basis of config name you can simply add an where condition in select query just like I am giving here, put whatever config_name you want to retrieve the query and it will print the config value which is there in the same row.

$this->db->select('config_value');
$q = $this->db->get_where('my_users_table',array('config_name'=>'home_page'));
$row = $q->row_array();
echo $row['config_name']; // this will print index.php 
piyush
  • 655
  • 4
  • 11
0

Little different than the other answers although functionally the same. You could make a helper and include this function. Really only useful if you only want to get one config item at a time.

function config_item_db($key)  {

    $CI = & get_instance();
    $query = $CI->db->get_where('my_users_table', array('config_name' => $key));
    if ($query->num_rows() == 1) {
        return $query->row()->{$key};
    } else {
        return false;
    }

}
Alex
  • 9,215
  • 8
  • 39
  • 82
0

Use codeignitor's get_where() method and pass the select condtions in an array. Example:

$this->load->database();
$this->db->get_where('table_name', array('database_column_title' => $value1, 
'database_column_title' => $value2));