有没有一种方法可以根据用户帐户来唯一地查看数据? Codeigniter PHP [英] Is there a way to view data uniquely from depending on the user accounts? Codeigniter PHP

查看:36
本文介绍了有没有一种方法可以根据用户帐户来唯一地查看数据? Codeigniter PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个标签,我正在尝试创建房间预订,因此当 user1 登录并选择一个房间时,他将被引导到第一个标签上,然后他/她可以请求一个房间,然后,在成功请求一个房间之后,它将转到第二个选项卡进行查看。我已经成功做到了。

I have two tabs, I am trying to create a room reservation, so when the user1 logged in and will choose a room he will be directed on the first tab, then he/she can request for a room then, after it has successfully requested a room, it will go to the second tab for viewing. I have successfully done that.

问题是:当我更改任何用户帐户时,选项卡1中显示的可用数据就会像 user1 正在查看。怎么了当 user2 尚未请求任何房间时。因此,所有房间都应该在他/她的末端。

The problem is: When I change any user accounts, then the available data that are showin in tab 1 is placed in tab 2 like what user1 is viewing. How is it that? when user2 hasn't yet requested any rooms. Therefore, all rooms should be available on his/her end.

查看

第一个标签

<?php foreach($dorms as $dorm): ?>

<a class="text-decoration-none">
  <div class="col-md-6 mt-4" style="margin-left: 6rem;padding-bottom: 1rem;">
    <div class="card top-shadow" style="width: 12rem; text-align:center;display:inline-block;">
      <div class="card-body">
       
             // TAB 1 DATA
      </div>
    </div>
  </div>
</a>

<?php endforeach; ?>

第二个标签

<?php foreach($dormreservedas $dormres): ?>

<a class="text-decoration-none">
  <div class="col-md-6 mt-4" style="margin-left: 6rem;padding-bottom: 1rem;">
    <div class="card top-shadow" style="width: 12rem; text-align:center;display:inline-block;">
      <div class="card-body">
       
             // TAB 2 DATA
      </div>
    </div>
  </div>
</a>

<?php endforeach; ?>

控制器

public function home()
{
    // Check login
    if(!$this->session->userdata('student_logged_in')){
        redirect('students/login');
    }

    $data['title'] = 'Home';
    
    $data['dorms'] = $this->dorm_model->get_dorms();
    $data['dormreserved'] = $this->dorm_model->get_reserves();

    $this->load->view('templates/header', $data);
    $this->load->view('students/pages/home', $data);
    $this->load->view('templates/footer');

}

模型

在第一个选项卡上,这是我如何分隔请求的数据以放置在第二个选项卡上的方法

On the 1st Tab, here is how I separate the requested data to be placed on the 2nd Tab

public function get_dorms(){
    $this->db->where('id NOT IN(select dorm_id from reserves)');
    $this->db->order_by('id', 'DESC');
    $query = $this->db->get('dorms');
    return $query->result_array();
}

第二个标签页模型

public function get_reserves(){
    $this->db->join('reserves', 'reserves.dorm_id = dorms.id');
    $this->db->where('reserves.tenant_id', $this->session->userdata('student_user_id'));
    $query = $this->db->get('dorms');
    return $query->result_array();
}


推荐答案

我希望它适用于您。

public function get_dorms(){
    $this->db->where('id NOT IN(select dorm_id from reserves WHERE tenant_id = '".$this->session->userdata('student_user_id')."')');
    $this->db->order_by('id', 'DESC');
    $query = $this->db->get('dorms');
    return $query->result_array();
}

这篇关于有没有一种方法可以根据用户帐户来唯一地查看数据? Codeigniter PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆