Welcome Guest, Not a member yet? Register   Sign In
[Solved] Getting one value from row in database
#1

[eluser]riwakawd[/eluser]
Hi I am just wondering if I have my code correct for getting the value of my row.

I need to be able to get it from the setting table with group: config, and the key: config_meta_title

The value is the main item in that row I am after.

Is this code correct?

Model

Code:
function getTitle() {
  return $this->db->get('setting', array(
    ->where('group' => 'config'),
    ->where('key' => 'config_meta_title'),
    ->select('value') // Want to be able to return any thing in the value
  ))->row()->setting;
}

Not sure if need the => for select if just want to return whats in that value
Controller

Code:
function index() {
  $data['title'] $this->document->getTitle();
  $this->load->view('sample', $data);
}
#2

[eluser]mohssenvox[/eluser]
hi , change your code to:
Model:
Code:
public function getTitle() {
     $this -> db ->select("*");
     $this -> db -> where("group","config");
     $this -> db -> where("key","config_meta_title");
     $query=$this->db->get();
     return $query->result();
}
and your controller:
Code:
function index() {
  $this->load->model("your model");
  $data['title']= $this->your model->getTitle();
  $this->load->view('sample', $data);
}
#3

[eluser]riwakawd[/eluser]
[quote author="mohssenvox" date="1402896839"]hi , change your code to:
Model:
Code:
public function getTitle() {
     $this -> db ->select("*");
     $this -> db -> where("group","config");
     $this -> db -> where("key","config_meta_title");
     $query=$this->db->get();
     return $query->result();
}
and your controller:
Code:
function index() {
  $this->load->model("your model");
  $data['title']= $this->your model->getTitle();
  $this->load->view('sample', $data);
}
[/quote]

Would that return the value column from that row?

database looks like "setting_id, group, key, value"

value is text.
#4

[eluser]mohssenvox[/eluser]
your model query return like: "select * from your table where group="config" and key="config_meta_data"
if you need only value column you can do this:"select value from your table where group="config" and key="config_meta_data"
#5

[eluser]riwakawd[/eluser]
[quote author="mohssenvox" date="1402900450"]your model query return like: "select * from your table where group="config" and key="config_meta_data"
if you need only value column you can do this:"select value from your table where group="config" and key="config_meta_data" [/quote]

I tried it did not select the value from that row

database http://postimg.org/image/izoi3dfg9/
#6

[eluser]mohssenvox[/eluser]
what is your table name?
#7

[eluser]riwakawd[/eluser]
[quote author="mohssenvox" date="1402905835"]what is your table name?[/quote]

$this->db->get('setting'); // Table Name

http://postimg.org/image/izoi3dfg9/

$this->db->where('group', 'config');

$this->db->where('key', 'config_meta_title');

$this->db->where('value'); // Need to get content

#8

[eluser]mohssenvox[/eluser]
use this in your model:
Code:
$this -> db->select("value");
$this->db->from(‘setting’); // Table Name
$this->db->where(‘group’, ‘config’);
$this->db->where(‘key’, ‘config_meta_title’);
$query=$this->db->get();
return $query->result();
and in your controller you can use this code to get value contet:
Code:
$this->load->model("your model");
$data=$this->your model->your function();
foreach($data as $index)
{
   echo $index->value;//you can access content
}
#9

[eluser]CroNiX[/eluser]
Code:
public function getField($fieldName) {
     $this -> db ->select($fieldName);
     $this -> db -> where("group","config");
     $this -> db -> where("key","config_meta_title");
     $query=$this->db->get('setting');
     return $query->row()->$fieldName; //return the column value of $fieldName
}

$value = $this->document->getField('value');
#10

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1402932939"]
Code:
public function getField($fieldName) {
     $this -> db ->select($fieldName);
     $this -> db -> where("group","config");
     $this -> db -> where("key","config_meta_title");
     $query=$this->db->get('setting');
     return $query->row()->$fieldName; //return the column value of $fieldName
}

$value = $this->document->getField('value');
[/quote]

Thanks for that works now. I know know what to do cheers.




Theme © iAndrew 2016 - Forum software by © MyBB