codeigniter中的列总和

时间:2017-08-03 13:24:51

标签: php mysqli codeigniter-3

遇到PHP错误 严重性:注意 消息:尝试获取非对象的属性

$query = $this->db->query("Select count(id) as count From `bookings` where status=6");
$row = $query->row('bookings');
echo $row->count;

1 个答案:

答案 0 :(得分:1)

检查此代码,它将返回所有行号,如果未找到任何数据,则返回未找到的数据。

$query = $this->db->query("select count(id) as count From bookings where status=6");
  if($query->num_rows() > 0 )
  {
     $row =  $query->row();
     echo  $row->count; // return the count
  } else {
      echo 'no data found';
  }

或者您可以使用num_rows()

$query = $this->db->query('select count(id) as count From bookings where status=6');
echo $query->num_rows();

希望它会帮助你