dsbqfrr098575666 2017-09-09 07:30
浏览 20
已采纳

无法使用codeigniter列出另一个表数据

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>
  • 写回答

2条回答 默认 最新

  • douduoting8408 2017-09-09 09:47
    关注

    Thanks, I have solved the problem.

    I have not loaded the model in the __construct() function.

    Added $this->load->model('centers_model','',TRUE); and the code works fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探