codeigniter - PHP Foreach for single result?
921
So in codeigniter I have the following in a model:
function get_product_requirements()
{
$query = $this->db->get_where('settings', array('name' => 'product_laws'));
return $query->result_array();
}
As you could guess this only returns one value. Right now I have a foreach to display this in the browser. It doesn't make sense to me to put a foreach for a single returned value.
<?php foreach($laws as $laws){ echo $laws['content']; } ?>
Is there an alternative to how I can display this item?
Answer
Solution:
CodeIgniter's Active Records have a native way of returning one row:
Then, to access your value, use this:
Read more about different ways to fetch rows here: http://ellislab.com/codeigniter/user-guide/database/results.html
Answer
Solution:
if you sure that you get one row every time you can write your model code in this way:
and get your content with:
but if you want to stay on your way you can access to your data with
reference: http://ellislab.com/codeigniter/user-guide/database/results.html