[eluser]penta997[/eluser]
Helo. I have a problem with displaying data from model. Instead subcategory list, controller displaying only the last record from subcategorys. This is my model code:
Code:
<?php
class Kategorie_model extends Model
{
function Kategorie()
{
parent::Model();
}
function get_category()
{
$this->db->query("Select * from category order by CAT_ID");
return $this->db->get('category');
}
function get_sub_category($id)
{
$result = $this->db->query("Select SUBC_Name from sub_category where CATEGORY_CAT_ID = '".$id."'");
return $result;
}
}
?>
and this is controller:
Code:
<?php
class Ksiegarnia extends Controller
{
function Ksiegarnia()
{
parent::Controller();
$this->load->model('Kategorie_model');
$this->response = array();
}
function main()
{
$view['left'] = $this->get_category();
$view['right'] = $this->load->view('Ksiegarnia/right', '', true);
$view['center'] = $this->load->view('Ksiegarnia/main', array('pierwszy' => 'pierwszy post'), true);
$this->load->view('Ksiegarnia/index', $view);
}
function news()
{
$view['left'] = $this->get_category();
$view['right'] = $this->load->view('Ksiegarnia/right', '', true);
$view['center'] = $this->load->view('Ksiegarnia/main', array('first' => '2nd click'), True);
$this->load->view('Ksiegarnia/index', $view);
}
function get_category()
{
$query = $this->Kategorie_model->get_category();
$this->response['subcategory'] = '';
$this->response['category'] = '';
$subcategory = '';
if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
$subcategory = $this->get_sub_category($item->CAT_ID);
$this->response['category'] .= $this->load->view('Ksiegarnia/left', array('category' =>$item, 'subcategory'=>$subcategory), true);
}
}
$data = $this->response['category'];
return $data;
}
function get_sub_category($id)
{
$this->response['result'] = '';
$query = $this->Kategorie_model->get_sub_category($id);
foreach($query->result() as $row)
{
$this->response['result'] = $row;
}
return $this->response['result'];
}
}
?>
I need help, please.