I'm using codeigniter and I wanted to make table that show my rating data on specific users.
This is how i wanted it to be:
但结果是这样的:
这是我的控制器
public function datarating()
{
$data['title'] = 'Data Rating';
$data['rating'] = $this->some_model->get_rating_data();
$this->load->view('template/navbar', $data);
$this->load->view('admin/item/rating_page', $data);
$this->load->view('admin/script/script', $data);
$this->load->view('template/footer');
}
这是我的模特
public function get_rating_data() {
$this->db->select('*');
$this->db->from('itemsrating');
$this->db->join('users', 'itemsrating.id_user = users.id_user');
$this->db->join('items', 'itemsrating.id_item = items.id_item');
$query = $this->db->get();
return $query->result();
}
这是我的观点
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="box-title">Data Rating</h4>
</div><!-- /.box-header -->
<div class="panel-body">
<div class="table-responsive" style="height: 400px ;overflow-y: scroll; ">
<table id="" class="table-condensed table-bordered table-striped">
<thead>
<th>Username</th>
<?php foreach ($rating as $row) { ?>
<th style="max-width: 120px"><?php echo "$row->item_name";?></th>
<?php } ?>
</thead>
<tbody>
<?php foreach ($rating as $row) {?>
<tr>
<td>
<?php echo "$row->username";?>
<?php foreach ($rating as $row) { ?>
<td><?php echo "$row->rating";?></td>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
&#13;
这是我在数据库中的表
id_user id_item rating date komentar
U0000000001 V0000000001 3 2016-11-09
U0000000002 V0000000002 4 2016-11-09
U0000000003 V0000000003 5 2016-11-09