![]() |
[Solved] Getting one value from row in database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [Solved] Getting one value from row in database (/showthread.php?tid=60727) |
[Solved] Getting one value from row in database - El Forum - 06-15-2014 [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() { Not sure if need the => for select if just want to return whats in that value Controller Code: function index() { [Solved] Getting one value from row in database - El Forum - 06-15-2014 [eluser]mohssenvox[/eluser] hi , change your code to: Model: Code: public function getTitle() { Code: function index() { [Solved] Getting one value from row in database - El Forum - 06-15-2014 [eluser]riwakawd[/eluser] [quote author="mohssenvox" date="1402896839"]hi , change your code to: Model: Code: public function getTitle() { Code: function index() { Would that return the value column from that row? database looks like "setting_id, group, key, value" value is text. [Solved] Getting one value from row in database - El Forum - 06-15-2014 [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" [Solved] Getting one value from row in database - El Forum - 06-16-2014 [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/ [Solved] Getting one value from row in database - El Forum - 06-16-2014 [eluser]mohssenvox[/eluser] what is your table name? [Solved] Getting one value from row in database - El Forum - 06-16-2014 [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 [Solved] Getting one value from row in database - El Forum - 06-16-2014 [eluser]mohssenvox[/eluser] use this in your model: Code: $this -> db->select("value"); Code: $this->load->model("your model"); [Solved] Getting one value from row in database - El Forum - 06-16-2014 [eluser]CroNiX[/eluser] Code: public function getField($fieldName) { [Solved] Getting one value from row in database - El Forum - 06-16-2014 [eluser]riwakawd[/eluser] [quote author="CroNiX" date="1402932939"] Code: public function getField($fieldName) { Thanks for that works now. I know know what to do cheers. |