在我看来,我正在尝试计算行数。根据计数,我想省去最后三行,并在我的视图中显示剩余的数量 我的控制器:
$data['info'] = $this->TrainingEvaluationModel->getQ();
$this->load->view('TrainingEvaluationView', $data);
显示数据来自的模型:
function getQ() {
$sql = $this->db->get('training_evaluation_entry');
return $sql->result();
}
我的观点如下:
<?php
foreach ($info as $row){
echo "<div class='row'>";
$i=$row->id;
echo "<div class='firstc'>".$row->id ."</div>";
echo "<div class='secondc'>".$row->name ."</div>";
echo '<input type="hidden" name="training_evaluation_entry_id'.$i.'" value='.$i.'>';
echo '<input type= "radio" name="group'.$i.'" value="strongly agreed"> Strongly Agreed';
echo '<input type= "radio" name="group'.$i.'" value="agreed"> Agreed';
echo '<input type= "radio" name="group'.$i.'" value="neutral">neutral';
echo '<input type= "radio" name="group'.$i.'" value="disagree">disagree';
echo '<input type= "radio" name="group'.$i.'" value="strongly disagree">strongly disagree';
echo "</div>";
}
?>
<input id="submit" type="submit" value="Submit" name="Submit">
</form>
我怎么能省去显示的最后三行?我正在使用codeigniter。请帮忙。感谢
答案 0 :(得分:1)
您可以使用count()
查看您有多少行,并array_splice()
在开始循环之前删除最后3项:
if (count($info) > 10) {
array_splice($info, -3);
}
foreach ($info as $row) {
...
您没有根据计数指定您真正想要遵循的规则。如果我们从超过10个项目开始,上面的代码将丢弃最后三个项目 - 应该很容易适应您需要的确切规则。