控制器:
public function searchevent() {
$this->load->model("users_model");
$data["rows"] = $this->users_model->search_member_events();
$this->load->view("search_view", $data);
}
模型:
public function search_member_events() {
$this->db->select('*');
$this->db->from('users');
$this->db->where('id', '$userid');
$this->db->join('events', 'users.id = events.user_id');
$q = $this->db->get();
if ( $q->num_rows() > 0 ) {
foreach ( $q->result() as $row ) {
$data[] = $row;
}
return $data;
}
}
看法:
<div class="member_search_results">
<h2>Your Events </h2>
<?php if(isset($rows)) : foreach($rows as $r): ?>
<div class="outer">
<div class='single_result'>
<strong class='title'><?php echo $r->title ?></strong>
<div class="outer">
<span class='start'><strong>Starts at:</strong> <?php echo $r->start ?></span>
<span class='end'><strong>Ends at:</strong> <?php echo $r->end ?></span>
<span class='time'><strong>Time:</strong><?php echo $r->time ?></span>
</div>
<div class="outer">
<span class='location'><strong>Location:</strong><?php echo $r->location ?></span>
</div>
<div class="outer">
<span class='description'><strong>Details:</strong><?php echo $r->description ?></span>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<h2>You do no have any events yet, please <?php echo anchor ("createevent", "Create Event") ?></h2>
<?php endif; ?>
</div>
我有两个数据库表用户和事件。我想要的是当用户登录时..来自 EVENT 表的登录用户的所有事件都应该显示在用户仪表板上。现在它正在显示所有事件。