php - Get categorised result taking arguments present inside loop codeigniter -


i have got 2 tables 'category' , 'organization' . under view want list organizations work under respective categories of category table . did shown below :

*here's controller : *

function organization() {        $data['category'] = $this->category_model->get_all_category();     $data['organization'] = $this->organization_model->get_categorised_organization();             $data['title'] = "welcome organization page";             $this->load->view('organization_index',$data); } 

here's model :

 function get_categorised_organization()     function get_categorised_organization() {         $category = $this->category_model->get_all_category();         $i = 0;         foreach ($category $c):             $sql = "select * ss_organization 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 $c):             $sql = "select * ss_organization org_working_area='$c->category_name'";             $query = $this->db->query($sql);             $result[] = $query->result();         endforeach;         return $result;     } 

and here's view

 <?php foreach($category $c): ?>     <div class="categorybox">         <h2><?php echo $c->category_name;?></h2><hr>         <ul>           <?php //print_r($organization); die();?>          <?php foreach($organization $o):?>            <?php foreach($o $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 i'm getting same organizations on different categories .. how can respective organizations working under respective category

i make version of this, , please adapt code

controller:

function organization() {      $this->load->model('mymodel');     $data['category'] = $this->mymodel->getallcategory();     $data['title'] = "welcome organization page";             $this->load->view('organization_index',$data); } 

model:

public function getallcategory() {     $query = $this->db->get('category');      if($this->db->_error_number() > 0)     {         return false;     }     else     {         return $query->result_array();     } }  function getorganizationbycategory($category_id) {      $this->db->where('category_id = ' . (int)$category_id);      $query = $this->db->get('ss_organization');     if($this->db->_error_number() > 0)     {         return false;     }     else     {         return $query->result_array();     } } 

view:

<?php foreach($category $c): ?>   <div class="categorybox">     <h2><?php echo $c['name'];?></h2><hr>     <ul>       // here call function display organizations category       <?php $organization = $this->mymodel->getorganizationbycategory($c['id']);?>       <?php foreach($organization $o):?>          <li><a href="#"><?php echo $o['name'];?></a></li>       <?php endforeach; ?>     </ul>   </div> <?php endforeach; ?> 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -