【发布时间】:2015-07-13 05:58:21
【问题描述】:
努力构建 html 表格布局。这是我要显示的内容:
Player | Week 1 | Week 2 | Week 3
1 | 11 | 19 | 7
2 | 14 | 12 | 10
3 | 9 | 15 | 13
但这就是我所能得到的一切:
Player | Week 1 | Week 2 | Week 3
1 | 11 | |
1 | 19 | |
1 | 7 | |
2 | 14 | |
2 | 12 | |
2 | 10 | |
3 | 9 | |
3 | 15 | |
3 | 13 | |
值来自单个表 (results),其中包含“玩家”、“周”和“分数”列
这是模型中的函数:
public function get_results(){
for($plyr=1;$plyr<3;$plyr++) {
$this->db->select('player, week, score');
$this->db->from('results');
$this->db->group_by(array('player','week'));
$query = $this->db->get();
return $query->result();
}
}
这里是视图:
<?php foreach($results as $result) : ?>
<tr>
<td><?php echo $result->player; ?></td>
<td><?php echo $result->score; ?></td>
</tr>
<?php endforeach; ?>
我不知道如何循环显示它,如上所示。我尝试在视图中嵌套 foreach 循环,但没有运气。想不出嵌套的 foreach 在模型函数中是如何工作的,特别是因为我只希望玩家 # 只迭代一次,而他们的每周得分都在同一行中。
编辑:我让表格更清晰
【问题讨论】:
标签: php mysql foreach codeigniter