如何在Codeigniter中加入2表

如何在Codeigniter中加入2表

数据存储在数据库中,但无法显示在页面中。请帮帮我

表项目

Project_ID,
项目名,
Project_Desc,
用户身份

表用户

用户名,用户名

这是我在模型中的代码

public function get_all_project()  {

$this->db->select('*');
$this->db->from('user');
$this->db->join('project','project.User_ID = user.User_ID');
$query = $this->db->get();
return $query->result();

}


这是我在控制器中的代码

    public function list_all_project() {

    $data['projectadmin_list'] = $this->projectadmin_model->get_all_project();
    $this->load->view('projectadmin_list',$data);
    $this->load->model('projectadmin_model');
  }


这是我的代码

    <?php

        foreach ($projectadmin_list as $data){ ?>

     <tr>
      <td><?php echo $data->Project_ID; ?></td>
      <td><?php echo $data->Project_Name; ?></td>
      <td><?php echo $data->Project_Desc; ?></td>
      <td><?php echo $data->Project_Total; ?></td>
      <td><?php echo $data->User_ID; ?></td>

      <td width="60" align="left" ><a href="#" onClick="show_confirm('edit',<?php echo $data->Project_ID;?>)">Edit</a></td>
      <td width="60" align="left" ><a href="#" onClick="show_confirm('delete_project',<?php echo $data->Project_ID;?>)">Delete </a></td>

     </tr>
    <?php }?>

最佳答案

在使用模型方法之前先加载模型

public function list_all_project() {
    $this->load->model('projectadmin_model'); // should be load here
    $data['projectadmin_list'] = $this->projectadmin_model->get_all_project();
    $this->load->view('projectadmin_list',$data);

  }

关于php - 如何在Codeigniter中加入2表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44480919/

10-13 06:06