简体   繁体   English

如何按编号显示? 笨

[英]How to display by id? codeigniter

I have three tables: 我有三个表:

EVENTS 活动

evid - pk 狂热-PK

evname EVNAME

evdate evdate

USERS USERS

eventid - fk 事件ID-FK

userid - pk 用户名-pk

username 用户名

TIME_SIGN TIME_SIGN

userid - fk 用户ID-FK

timeid - pk 时光-pk

timeDT timeDT


I want to get the records of the users who have the particular eventid 我想获取具有特定事件标识的用户的记录

So in my previous view there is a button to be clicked to view the list of registered users of that particular event. 因此,在我以前的视图中,有一个按钮可以单击以查看该特定事件的注册用户列表。

Controller File: events.php (index) 控制器文件:events.php(索引)

function index()
{
    $data['events'] = $this->model_events->getusersbyid();
    $this->load->view('viewEvents', $data);
}

View File: viewEvents.php 查看文件:viewEvents.php

<?php foreach ($events as $event): ?>
              <div class="col-sm-6 col-md-4" style="width:200px; height:200px;">
                <div class="thumbnail">
                  <img src="<?php echo base_url(); ?>assets/images/eventi.png" alt="image-only">
                  <div class="caption">
                    <h3><?=$event->eventID;?></h3>
                    <h3><?=$event->eventName;?></h3>
                    <h4><?=$event->eventDate;?></h4>
                    <a href="<?php echo base_url()."index.php/events/showRegList/".$event->eventID; ?>" class="btn btn-primary" role="button">View Users</a>
                  </div>
                </div>
              </div>
      <?php endforeach; ?>

Now this part: 现在这部分:

<a href="<?php echo base_url()."index.php/events/showRegList/".$event->eventID; ?>" class="btn btn-primary" role="button">View Users</a>

I'm trying to get the ID of the event. 我正在尝试获取事件的ID。 Currently, I have only 2 events and 3 users. 目前,我只有2个事件和3个用户。 In Event1 there is User1 and User2 and in Event2 there is only User3. 在Event1中有User1和User2,在Event2中只有User3。 But what happens in the display is it displays all the users. 但是显示中发生的是它显示了所有用户。 Both, in Event1 and Event2 views. 两者都在Event1和Event2视图中。

This is the model for my view file in displaying the records. 这是显示记录时我的视图文件的模型。 What am I missing or what could be wrong with my code? 我缺少什么或者我的代码可能有什么问题?

Model File: model_events.php (display_table) 模型文件:model_events.php(display_table)

function display_table()
{
      $this->db->select("events.eventID, users.id, users.event_id, CONCAT(lname, ', ', fname, ' ', mname) AS name, users.position,  time_sign.indexuser, time_sign.timein, time_sign.timeout");
      $this->db->from('events');
      $this->db->join('users', 'users.event_id = events.eventID', 'LEFT');
      $this->db->join('time_sign', 'time_sign.indexuser = users.id', 'LEFT');
      $query = $this->db->get();
      return $query->result();
}

This is the view of the list: 这是列表的视图:

<?php foreach ($events as $event): ?>
           <tr>
               <td class="hidden"><?=$event->id;?></td>
               <td><?=$event->name;?></td>
               <td><?=$event->position;?></td>
               <td><?=$event->timein;?></td>
               <td><?=$event->timeout;?></td>
               <td width="100px">
                   <a href="<?php echo base_url()."index.php/tabledisplay/recTime/".$event->id; ?>">
                       <button type="submit" class="btn btn-success" name="time-in" style="margin:3px">Sign In</button>
                   </a>
                   <a href="<?php echo base_url()."index.php/tabledisplay/recOut/".$event->id; ?>">
                       <button type="submit" class="btn btn-danger" name="time-in" style="margin:3px">Sign Out</button>
                   </a>
               </td>
               <td>
                   <a href="<?php echo base_url()."index.php/events/show_recid/".$event->id; ?>">
                    <button type="button" class="btn btn-info" aria-label="Left Align">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                       </button></a>
                   <a href="<?php echo base_url()."index.php/events/delete/".$event->id; ?>">
                   <button type="button" class="btn btn-danger" aria-label="Left Align">
                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                       </button></a>
               </td>
           </tr>
          <?php endforeach; ?>

And this is the controller for displaying the list: EVENTS.php 这是用于显示列表的控制器:EVENTS.php

(I put a comment below because that was my idea of getting the ID but doesn't work) (我在下面发表评论,因为那是我获取ID的想法,但不起作用)

function showRegList()
{
    $data = array();
    $id = $this->uri->segment(3);
    //$evID = $this->model_events->getusersbyid();
    $data['events'] = $this->model_events->display_table();
    $this->load->view('table_view', $data);
}

THANK YOU. 谢谢。

If I'm understanding what you are asking correctly, I think you just need to add a where clause to your SQL in the model and pass the event ID to it from the controller script. 如果我理解正确的要求,我认为您只需要在模型中的SQL中添加where子句,然后将事件ID从控制器脚本传递给它即可。

First up the Events.php controller script. 首先启动Events.php控制器脚本。

function showRegList()
 {
    $data = array();
    $id = $this->uri->segment(3);
    //$evID = $this->model_events->getusersbyid();
    $data['events'] = $this->model_events->display_table($id);
    $this->load->view('table_view', $data);
 }

Second, model_events.php. 第二,model_events.php。 You will be returning everything because there's no where clause in your statement. 您将返回所有内容,因为语句中没有where子句。

function display_table($event_id)
{
  $this->db->select("events.eventID, users.id, users.event_id, CONCAT(lname, ', ', fname, ' ', mname) AS name, users.position,  time_sign.indexuser, time_sign.timein, time_sign.timeout");
  $this->db->from('events');
  $this->db->join('users', 'users.event_id = events.eventID', 'LEFT');
  $this->db->join('time_sign', 'time_sign.indexuser = users.id', 'LEFT');
  $this->db->where('events.evid',$event_id);
  $query = $this->db->get();
  return $query->result();
}

Hopefully that should get you on the right track. 希望那能使您走上正确的道路。

Try This code Events Controller 试试此代码事件控制器

function showRegList()
{
    $data = array();
    $id = $this->uri->segment(3);
    $data['events'] = $this->model_events->display_table($id);
    $this->load->view('table_view', $data);
}

Model File: model_events.php (display_table) 模型文件: model_events.php (display_table)

    function display_table($id)
    {
          $this->db->select("events.eventID, users.id, users.event_id, CONCAT(lname, ', ', fname, ' ', mname) AS name, users.position,  time_sign.indexuser, time_sign.timein, time_sign.timeout");
          $this->db->from('events');
          $this->db->join('users', 'users.event_id = events.eventID', 'LEFT');
          $this->db->join('time_sign', 'time_sign.indexuser = users.id', 'LEFT');
          $condition=array("events.eventID"=>$id)
          $this->db->where($condition);
          $query = $this->db->get();
          return $query->result();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM