Welcome Guest, Not a member yet? Register   Sign In
Selecting category details and products linked with the same category.
#11

[eluser]cideveloper[/eluser]
Controller
Code:
function index() {

    $build_array = array();
    $fleets = $this->Fleets_model->select_fleets();
    foreach($fleets as $row){
        $build_array[] = array (
            'fleets_array' => $row,
            'listefleets_array' => $this->Fleets_model->list_fleets($row['category_id'])
        );
    }
    $data = array (
        'meow' => $build_array
    );
    $this->load->view('fleets',$data);    
}

Models - Change it to return Array

Code:
function select_fleets() {
    $this->db->select('car_category.category_name, car_category.category_id, car_category.details');
    $this->db->from('car_category');
    $this->db->join('cars', 'cars.category_id = car_category.category_id');
    $result_product = $this->db->get();
    return $result_product->result_array();
}

function list_fleets($cid){
    $this->db->where('category_id',$cid);
    $result_product = $this->db->get('cars');
    return $result_product->result_array();
}

View

Code:
<div>
    &lt;?php
    foreach ($meow as $crow)
    {
        echo $crow['fleets_array']['category_name'] . '<br />' . chr(10);
        foreach ($crow['listefleets_array'] as $lrow)
        {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $lrow['car_name'] . '<br />' . chr(10);
        }
    }
    ?&gt;
</div>


Messages In This Thread
Selecting category details and products linked with the same category. - by El Forum - 02-05-2011, 12:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB