Welcome Guest, Not a member yet? Register   Sign In
Get a single value from a a database ?
#1

[eluser]chefnelone[/eluser]
Hello I have this funcion in a model.

I retrieve one value (product_name) for a table (products).
It works fine but... as you can see I'm using a foreaech() to echo the result.

Since I just get 1 result I don't want to use the foreach() statement.

Question: How do I echo the result NOT using foreach()

Code:
function get_product(){
  $this->db->where("product_id", "10");
  $this->db->limit(1);
  $query = $this->db->get('products');

  foreach ($query->result() as $row)
    {
     echo $row->product_name;
    }    
}

Thanks
#2

[eluser]n0xie[/eluser]
Code:
$this->db->select('product_name');
  $this->db->where("product_id", "10");
  $this->db->limit(1);
  $query = $this->db->get('products');
  
  echo $query->row()->product_name;




Theme © iAndrew 2016 - Forum software by © MyBB