我想显示表格中的某些列。另外,想要计算表中显示的总行数。我尝试了一些方法,如果这是正确的方法,或者还有其他更好的方法,请您帮助我。
我的模型
public function getRentedEquipments($project_id=0){
return $this->db->select('e.*, p.project_id')
->from('equipment AS e')
->join('project AS p', 'p.project_id = e.project_id')
->where('p.project_id', $project_id)
->order_by('eq_name','ASC' )
->get()->result_array();
}
我的看法
<tbody>
<?php
$total_eq=0;
$count=1;
foreach ($pr_eq as $row) {
?>
<tr>
<th scope="row"><?php echo $count;?></th>
<th scope="row"><?php echo $row['eq_id'];?> </th>
<th scope="row"><?php echo $row['eq_name'];?> </th>
<?php
$total_eq+=$row['eq_id']-1;
$count=$count+1;
}
?>
<button class="btn btn-info"> Number of Equipments: <?php echo $total_eq;?></button>
</tbody>
最佳答案
恕我直言,没有必要以这种方式计算您的元素 - 只需尝试一下
<tbody>
<?php
foreach ($pr_eq as $row)
{
?>
<tr>
<th scope="row"><?php echo $count;?></th>
<th scope="row"><?php echo $row['eq_id'];?> </th>
<th scope="row"><?php echo $row['eq_name'];?> </th>
</tr>
<?php
}
?>
</tbody>
<button class="btn btn-info"> Number of Equipments: <?= count($pr_eq);?></button>
关于php - 如何计算从数据库检索的 View 中的总行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48038581/