Welcome Guest, Not a member yet? Register   Sign In
Variables of single row in view
#1

[eluser]Fero[/eluser]
Hi,

This is my model function:
Code:
function nacitaj_produkt($id)
    {
      $query=$this->db->get_where('produkty',array('status'=>'1','id_produkty'=>$id));
      return $query->result();
    
    }

It loads one row of one product and returns it.

This is in one method of my controller:
Code:
$this->load->model('produkty_model');
      $product_data['product']=$this->produkty_model->nacitaj_produkt($id);
    
    $this->load->view('detail',$product_data);

in detail.php (view) I have no idea how to get those variables from database I got. echo $product->table_column; works only in loops in views, but it doens't work when there is only one row.
#2

[eluser]JoostV[/eluser]
Model
Code:
function nacitaj_produkt($id)
    {
      $query=$this->db->get_where('produkty', array('status' => '1', 'id_produkty' => $id));
      return $query->num_rows > 0 ? $query->row(); false;
    }

View
Code:
if($product != false) {
    echo $product->id_produkty;
}
#3

[eluser]Fero[/eluser]
Thx, actually, you pointed me to right direction with $query->row() and also to check if there was anything in the row at all :-)
#4

[eluser]JoostV[/eluser]
You're welcomeSmile More pointers about retrieving query results are in the userguide




Theme © iAndrew 2016 - Forum software by © MyBB