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!
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.
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.
Use row()
like,
return $this->db->get()->row()->name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With