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>
#12

[eluser]Bigil Michael[/eluser]
now i got the result like this

Group D
lancer1212
Group C
mercedes
benz 112
Group C
mercedes
benz 112
Group A
YARIS
Lancer
Group A
YARIS
Lancer

category names(group) are repeating
#13

[eluser]cideveloper[/eluser]
Ok then try this

Code:
function select_fleets() {
    return $this->db->get('car_category')->result_array();
}
#14

[eluser]Bigil Michael[/eluser]
thanku so much
now it is working but it generates another problem

this is my original controller
Code:
function index($pgoffset='')
    {
        $this->load->model('Home_model');
        $this->data['row_offer'] = $this->Home_model->select_offer();
        $this->data['result_news'] = $this->Home_model->select_news();
        
        $config['per_page'] = 2;
        $config['total_rows'] = $this->Fleets_model->get_total();
        $config['base_url'] = site_url().'/fleets/index/';
        $config['uri_segment'] = 3;
        $build_array = array();
        $fleets = $this->Fleets_model->select_fleets($config['per_page'], $pgoffset);
        
        foreach($fleets as $row){
            $build_array[] = array (
                'fleets_array' => $row,
                'listefleets_array' => $this->Fleets_model->list_fleets($row['category_id'])
            );
        }
        $this->data = array (
        'meow' => $build_array
        );
        $this->data['pgoffset'] = $pgoffset;
        $this->pagination->initialize($config);
        $this->data['pagetitle'] = 'Fleets & Rates';
        $this->load->view('fleets',$data);    
    }
iam sending another 2 results for that purticular view

$this->data['row_offer'] = $this->Home_model->select_offer();
$this->data['result_news'] = $this->Home_model->select_news();

these 2 steps are not working that means there show an error

Message: Undefined variable: row_offer
#15

[eluser]cideveloper[/eluser]
change
Code:
$this->data = array (
        'meow' => $build_array
        );

to

Code:
$this->data['meow'] = $build_array;

Read this
#16

[eluser]Bigil Michael[/eluser]
i solved my problem

thank you so much
#17

[eluser]Bigil Michael[/eluser]
order by and limit is not working
Code:
function select_fleets($limit, $pgoffset)
           {
        $this->db->limit($limit, $pgoffset);
                $this->db->order_by("category_name","ASC");
        $this->db->select('car_category.category_name, car_category.category_id, car_category.details, car_category.photo');
        $this->db->from('car_category');
        $this->db->join('cars', 'cars.category_id = car_category.category_id');
        $result_product = $this->db->get();
        return $this->db->get('car_category')->result_array();
        }

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

can u tell me how to apply limit and orderby category name ascending??
thanks in advance
#18

[eluser]Bigil Michael[/eluser]
Quote:function select_fleets($limit, $pgoffset)
{
$this->db->limit($limit, $pgoffset);
$this->db->order_by("category_name","ASC");
$this->db->select('car_category.category_name, car_category.category_id, car_category.details, car_category.photo');
$this->db->from('car_category');
$this->db->join('cars', 'cars.category_id = car_category.category_id');
$result_product = $this->db->get();
return $this->db->get('car_category')->result_array();
}

here limit and order_by is not working can anyone help me??????????

thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB