我是Codeigniter的新手,需要一些帮助。

我想在表格中显示一些列。另外,要计算表中显示的总行数。我尝试了一些方法,如果这是正确的方法,或者有其他更好的方法,可以请帮助我。

我的模特

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();
 }

My view


<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>







我在图片链接中的输出,

输出正确显示,只想知道是否有更好的方法可以做到这一点
mysql - Codeigniter:计算从数据库检索的 View 中的总行数-LMLPHP

最佳答案

恕我直言,无需以这种方式计算您的商品-只需尝试一下

<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>

关于mysql - Codeigniter:计算从数据库检索的 View 中的总行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48038581/

10-12 13:05
查看更多