Welcome Guest, Not a member yet? Register   Sign In
Why does it return only one data?
#1

[eluser]shinokada[/eluser]
I have the following model, control and view.
It returns only one data.

Could anyone point out what I am doing wrong please?

Model

Code:
function getGalleryone(){
  
   $data = array();
  
     $Q = $this->db->get('products');
    
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data['products'] = $row;
       }
      }
    
    $Q->free_result();
    
    return $data;
}

Control

Code:
function galleryone(){
    $data['title'] = "Gallerie 1";
    $data['products'] = $this->MProducts->getGalleryone();
// getGalleryone returns id, name shortdesc thumbnail image class grouping category
    $data['main'] = 'galleryone';// this is using views/galleryone.php
    $this->load->vars($data);
    $this->load->view('template');
  }

View

Code:
foreach ($products as $key =>$product)
{
echo "<pre>";    
print_r ($product);
echo "</pre>";
}
#2

[eluser]rogierb[/eluser]
You are overwriting the same variable: $data['products']
Code:
$data['products'] = $row;

It should be
Code:
$data['products'][] = $row;

or
Code:
$data['products'][$row->id] = $row;
#3

[eluser]shinokada[/eluser]
Thanks rogierb.




Theme © iAndrew 2016 - Forum software by © MyBB