管理员使用codeigniter分配数据后,当用户登录时如何从postgresql

我正在制作我有 1 个管理员和 10-15 个用户的项目。


对于每个用户,我只想向他们显示专门分配给他们的案例,以便在管理员分配时加载到他们的仪表板上。未分配给他们的案例不会列在他们的仪表板上。


管理员可以成功地将 case_id 分配给一个表


这是 case_assignment 表,其中包含 case_id(管理员分配的)、用户名(分配给谁的案例)、分配的日期。


类似的用户表有用户名、密码、级别(管理员为 1,所有其他用户为 2)、电子邮件


如果管理员已将案例(case_id 将存在)分配给 case_assignment 表中的特定用户名,那么当用户登录时,他应该能够看到与该特定 case_id 相关的所有数据(表)。这里是截图:


管理员页面:https : //prnt.sc/novscc --> 这将如何为管理员显示数据表。他将拥有所有案例数据。当他将案例分配给用户时。用户应该只收到这种情况。


用户页面:https : //prnt.sc/novtnr -> 这是我希望在管理员分配案例时显示用户数据表的方式。


这是数据库 case_assigment 表屏幕截图:https : //prnt.sc/novtze(这里只有管理员想要分配的 case_id 和用户名)。


这是视图,user.php


<table id="table" class="table table-striped table-bordered display nowrap" cellspacing="0" width="100%" "style="width: 650px;">

            <thead>

                <tr>

                    <th>Case ID</th>

                    <th>Case Name</th>

                    <th>Firm Name</th>

                    <th>Case Overview</th>

                    <th>Priority</th>

                    <th>Received Date</th>

                    <th>Expected Delivery Date</th>

                    <th>Service Status</th>

                </tr>

            </thead>

        <tbody>

                <?php


                        if($result){

                           foreach ($result as $results) {                                

                ?>

                <tr>

                    <td><?php echo $results->case_id; ?></td>

                    <td><?php echo $results->case_name; ?></td>

                    <td><?php echo $results->firm_name; ?></td>

                    <td><?php echo $results->case_description; ?></td>

                    <td><?php echo $results->priority; ?></td>

                    <td><?php echo $results->received_date; ?></td>

                    <td><?php echo $results->expected_delivery_date; ?></td>

                    <td><?php echo $results->service_status; ?></td>

                </tr> 

    <?php

            }

        }

    ?>



慕莱坞森
浏览 117回答 3
3回答

繁星coding

根据您的评论,我假设一名员工被分配到一个案例。因此:function get_employee_case() {&nbsp; &nbsp; $this->db->select('case_id');&nbsp; &nbsp; $this->db->where('username', $this->session->userdata('username'));&nbsp; &nbsp; $q = $this->db->get('case_assignment');&nbsp; &nbsp; if ($q->num_rows() == 1) {&nbsp; &nbsp; &nbsp; &nbsp; return $q->row()->case_id;&nbsp; &nbsp; }&nbsp; &nbsp; return null;}控制器:$case_id = $this->HomeModel->get_employee_case();if (!is_null($case_id)) {&nbsp; &nbsp; $data['result'] = $this->HomeModel->get_employee($case_id);} else {&nbsp; &nbsp; $data['result'] = null;}看法:if (is_null($result)) {&nbsp; &nbsp; echo 'no case assigned';} else {&nbsp; &nbsp; ...}

月关宝盒

这是我正在寻找的结果:Controller:&nbsp; &nbsp; &nbsp;public function index()&nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$data['result'] = $this->HomeModel->get_employee_case();&nbsp; &nbsp; &nbsp; &nbsp;$this->load->view('case/user');&nbsp; &nbsp; /*&nbsp; &nbsp; &nbsp; &nbsp;print_r($data);&nbsp; &nbsp; &nbsp; &nbsp;die; */&nbsp; &nbsp; }Model:&nbsp; &nbsp; function get_employee_case()&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $this->db->select('case_assignment.case_id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case_main.case_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case_main.firm_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case_overview.case_description,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case_priority.priority,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;service_delivery_dates.received_date,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;service_delivery_dates.expected_delivery_date,&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;service_delivery_dates.service_status');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->from('case_tracker.case_assignment');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.case_main', 'case_tracker.case_assignment.case_id=case_tracker.case_main.case_id', 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.case_overview', 'case_tracker.case_main.case_id=case_tracker.case_overview.case_id', 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.type_of_services', 'case_tracker.case_overview.case_id = case_tracker.type_of_services.case_id', 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.specific_instructions', 'case_tracker.type_of_services.case_id = case_tracker.specific_instructions.case_id' , 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.case_priority', 'case_tracker.specific_instructions.case_id = case_tracker.case_priority.case_id' , 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->join('case_tracker.service_delivery_dates', 'case_tracker.case_priority.case_id = case_tracker.service_delivery_dates.case_id' , 'left');&nbsp; &nbsp; &nbsp; &nbsp; $this->db->where('case_assignment.username', $this->session->userdata('username'));&nbsp; &nbsp; &nbsp; &nbsp; $query = $this->db->get();&nbsp; &nbsp; &nbsp; &nbsp; return $query->result();&nbsp; &nbsp; }

吃鸡游戏

您必须首先选择分配给用户的所有案例select&nbsp;*&nbsp;from&nbsp;cases&nbsp;where&nbsp;user_id=2获取循环中的所有案例然后为每个案例获取数据
打开App,查看更多内容
随时随地看视频慕课网APP