Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the value of the single field output using the codeigniter active record

Tags:

the following function is supposed to read the name of the given asset code from the database. but it triggers the error: "Trying to get property of non-object"

function sban_name($asset){     $this->db->select('name');     $this->db->from('asset_types');     $this->db->where('code',$asset);     return $this->db->get()->result()->row('name'); } 

All I want is to have the name of the asset returned back to the controller! Your help is highly appreciated!

like image 752
Reza Saberi Avatar asked Jun 06 '13 05:06

Reza Saberi


People also ask

What is Active Record in CodeIgniter?

Active Record Class CodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.

How do you get rows in CI?

If you require to get only one record from database table using codeigniter query then you can do it using row(). we can easily return one row from database in codeigniter. I will give you simple example of fetch single record from database using mysql codeigniter.


1 Answers

Use row() like,

return $this->db->get()->row()->name; 
like image 92
Rohan Kumar Avatar answered Oct 06 '22 23:10

Rohan Kumar