Reputation: 27
In my view I'm trying to count the number of rows. depending on the count i want to leave out last three rows and show the remaining in my view My controller:
$data['info'] = $this->TrainingEvaluationModel->getQ();
$this->load->view('TrainingEvaluationView', $data);
My Model from where the data is coming is shown:
function getQ() {
$sql = $this->db->get('training_evaluation_entry');
return $sql->result();
}
My view is given below:
<?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>
how can i leave out the last three rows from showing?? i am using codeigniter. please help. thanks
Upvotes: 0
Views: 1681
Reputation: 8174
You can use count()
to see how many rows you have, and array_splice()
to drop the last 3 items before you start your loop:
if (count($info) > 10) {
array_splice($info, -3);
}
foreach ($info as $row) {
...
You didn't specify what rules you actually wanted to follow depending on the count. The above code will drop the last three items if we're starting with more than 10 items - it should be easy to adapt to the exact rules you need.
Upvotes: 1