I have got two tables 'category' and 'organization' . Under my view i want to list all those organizations which work under respective categories of category table . What i did is shown below :
*Here's my controller : *
function organization()
{
$data['category'] = $this->category_model->get_all_category();
$data['organization'] = $this->organization_model->get_categorised_organization();
$data['title'] = "Welcome to the organization page";
$this->load->view('organization_index',$data);
}
Here's the model :
function get_categorised_organization() function get_categorised_organization() {
$category = $this->category_model->get_all_category();
$i = 0;
foreach ($category as $c):
$sql = "SELECT * FROM ss_organization where org_working_area='$c->category_name'";
$query = $this->db->query($sql);
$result[] = $query->result();
endforeach;
return $result;
} {
$category = $this->category_model->get_all_category();
$i = 0;
foreach ($category as $c):
$sql = "SELECT * FROM ss_organization where org_working_area='$c->category_name'";
$query = $this->db->query($sql);
$result[] = $query->result();
endforeach;
return $result;
}
and here's the view
<?php foreach($category as $c): ?>
<div class="categorybox">
<h2><?php echo $c->category_name;?></h2><hr>
<ul>
<?php //print_r($organization); die();?>
<?php foreach($organization as $o):?>
<?php foreach($o as $p): ?>
<li><a href="<?php echo base_url();?>index.php/home_controller/organization_detail/<?php echo $p->org_id;?>"><?php echo $p->org_name;?></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach;?>
Now what i'm getting is same organizations over different categories .. How can i get respective organizations working under the respective category