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

[eluser]Bigil Michael[/eluser]
i want to list car category name and car details in a single page

but the result is car details are same for every category....
can anyone help me .....

thanks in advance


controller
Code:
function index()
    {
        
    $fleets = $this->Fleets_model->select_fleets();
    $this->data['fleets'] = $fleets;
        foreach($fleets as $row)
        {
         $cid = $row->category_id;
         $this->data['listefleets'] = $this->Fleets_model->list_fleets($cid);
        }
    $this->load->view('fleets',$this->data);    
    }

model
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();
   }
function list_fleets($cid)
   {
   $this->db->where('category_id',$cid);
   $result_product = $this->db->get('cars');
   return $result_product->result();
   }
view
Code:
<?php foreach($fleets as $row)
{
?>
   <?php echo $row->category_name;?>
      
     <?php foreach($listefleets as $row)
     {
     ?>
         <?php echo $row->car_name;?>
     <?php
      }
     ?>
}
?>


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



Theme © iAndrew 2016 - Forum software by © MyBB