Codeigniter - Sql 数据库

Codeigniter - Sql Databases

我用了 2 tables。 table 中的第一个是部门。我想在用户的个人资料页面中显示部门。用户可以在个人资料页面编辑部门。但首先他可以在个人资料页面和个人资料编辑页面中看到自己的部门。但是个人资料页面和个人资料编辑页面都没有部门字段。也许我可以这样做吗?

我的代码如下:

个人资料的控制者:

public function index()
    {

        $viewData = new stdClass();
        $viewData->user = $this->db->get("user")->result();
        $viewData->departments = $this->db->get("department")->result();
        $this->lang->load('content', $this->session->userdata('userLang'));
        $this->load->view('profile', $viewData);
    }

我对个人资料的看法:

<aside class="profile-info col-lg-9">
                <section class="panel">
                    <div class="bio-graph-heading">
                        <?php echo $this->lang->line('profile_top_profile_text'); ?>
                    </div>
                    <div class="panel-body bio-graph-info">
                        <h1><?php echo $this->lang->line('profile_text_informations'); ?></h1>
                        <div class="row">
                            <div class="bio-row">
                                <p><span><?php echo $this->lang->line('profile_first_name'); ?></span>: <?php echo $this->session->userdata('people_name'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span><?php echo $this->lang->line('profile_last_name'); ?> </span>: <?php echo $this->session->userdata('people_surname'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Username </span>: <?php echo $this->session->userdata('people_username'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Email </span>: <?php echo $this->session->userdata('people_email'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Language</span>: <?php if ($this->session->userdata('people_lang') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Department </span>: <?php if ($this->session->userdata('people_department') == $departments->departmentId) { echo $departments->departmentName;} ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>User Type</span>: <?php if ($this->session->userdata('people_department') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>User Status</span>: <?php echo ($this->session->userdata('people_status') == 1) ? "<span class='label label-success''>Active</span>" : "<span class='label label-danger''>Deactive</span>" ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Registered Date </span>: <?php echo $this->session->userdata('people_date'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Modified Date </span>: <?php echo $this->session->userdata('people_mdate'); ?></p>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>

部门数据库:

CREATE TABLE `department` (
  `departmentId` int(11) NOT NULL AUTO_INCREMENT,
  `departmentOffice` int(11) NOT NULL,
  `departmentName` varchar(80) COLLATE utf8_turkish_ci NOT NULL,
  `departmentAuthPerson` int(11) DEFAULT NULL,
  PRIMARY KEY (`departmentId`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;

我应该这样做吗?或者我能为此做些什么?感谢您的帮助,大社区。

希望对您有所帮助:

在索引方法中使用 row() 而不是 result()

public function index()
{
   $viewData = new stdClass();
   $viewData->user = $this->db->get("user")->result();
   $viewData->departments = $this->db->get("department")->row();
   $this->lang->load('content', $this->session->userdata('userLang'));
   $this->load->view('profile', $viewData);
}