Noob: Dealing with a Single Query Result |
[eluser]ebohling[/eluser]
I know there has to be a better way to access a single db result (select opportunity_name from an id) then this: $this->db->select('opportunity_name'); $this->db->from('Opportunities'); $this->db->where('opportunity_id', (int)$new->contribution_opportunity_id); $query = $this->db->get(); foreach ($query->result() as $row) // there has to be a better, more efficient way! { $new->opportunity_name = $row->opportunity_name; } But after scouring the forums and trying my darnedest, I cannot figure it help.
[eluser]n0xie[/eluser]
Try this (don't need the foreach loop) : Code: $query->row()->opportunity_name;
[eluser]ebohling[/eluser]
while i could not get your sample to work (got same convert error as i was getting when i was trying), but i followed your link and came up with this: $this->db->select('opportunity_name'); $this->db->from('Opportunities'); $this->db->where('opportunity_id', (int)$new->contribution_opportunity_id); $query = $this->db->get(); if ($query->num_rows() > 0) { $row = $query->row(); $new->opportunity_name = $row->opportunity_name; } else { $new->opportunity_name = 'an opportunity was not selected'; }
[eluser]Thorpe Obazee[/eluser]
[quote author="ebohling" date="1245218478"]while i could not get your sample to work (got same convert error as i was getting when i was trying) [/quote] You're probably using PHP 4. [quote author="ebohling" date="1245218478"] Code: $this->db->select('opportunity_name'); Try to put your code in [ code] tags
|
Welcome Guest, Not a member yet? Register Sign In |