Edit: [Solved] - Did not load the model.
I'm able to display the list of groups fetched from the table. But unable to display the list of centers.
I'm unable to find where I have made an error.
When I uncomment the $data['allcenters']
, I just get an empty page. But when I remove the line, the page displays fine but without the list of centers.
The table name of groups is user_groups. The table name of centers is institute_data.
The code is as below:
Controller: (user_data.php)
function add_new(){
$logged_in=$this->session->userdata('logged_in');
if($logged_in['su']!="1"){
exit('Permission denied');
return;
}
$data['title']="Add User";
//get the list of the groups
$data['allgroups'] = $this->group_model->get_allgroups();
//get the list of all centers
$data['allcenters'] = $this->centers_model->get_allcenters();
//Page is displayed when the above code is commented.
//On inserting the above line, the page is just blank
$this->load->view($this->session->userdata('web_view').'/header',$data);
$this->load->view($this->session->userdata('web_view').'/add_user',$data);
$this->load->view($this->session->userdata('web_view').'/footer',$data);
}
Model (centers_model.php):
function get_allcenters(){
$query = $this->db->get("institute_data");
$result = $query->result_array();
return $result;
}
Model (group_model.php):
function get_allgroups(){
$query = $this->db->get("user_group");
$result = $query->result_array();
return $result;
}
View (add_user.php)
<?php print_r($allcenters); ?>
<div class="form-group">
<label>Center </label>
<select class="form-control" name="centers">
<?php foreach($allcenters as $key => $center){ ?>
<option value="<?php echo $center['su_institute_id']; ?>"><?php echo $center['organization_name']; ?></option>
<?php } ?>
</select>
</div>
<?php print_r($allgroups); ?>
<div class="form-group">
<label>Group </label>
<select class="form-control" name="user_group">
<?php foreach($allgroups as $key => $group){ ?>
<option value="<?php echo $group['gid']; ?>"><?php echo $group['group_name']; ?></option>
<?php } ?>
</select>
</div>