CodeIgniter Forums
Query for 1 variable from database table. Looking for optimized code. - 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: Query for 1 variable from database table. Looking for optimized code. (/showthread.php?tid=28312)



Query for 1 variable from database table. Looking for optimized code. - El Forum - 03-07-2010

[eluser]brandontran[/eluser]
I can get the variable 'country' from the database table,but it isn't very clean looking to me.

To all the code optimizers out there, what is the simplest way to get the variable country from this table?


$this->db_dash->select('country');
$this->db_dash->where('country_code', $country_code);
$query = $this->db_dash->get('country_table');
if ($query->num_rows() > 0)
{
$row = $query->row();
$country_title = $row->country;
}



Query for 1 variable from database table. Looking for optimized code. - El Forum - 03-07-2010

[eluser]Christopher Blankenship[/eluser]
Code:
$limit = 1;
$query = $this->db_dash->get_where('country', array('country_code' => $country_code), $limit);
This would be one way to clean up your code using get_where().