用codeigntier显示计数行

时间:2016-05-06 06:35:46

标签: jquery codeigniter-3

我想计算今天活跃的所有行 但我无法计算

模型

public function aantal_externe_today()
{
$this->db->select_count('doel');
$this->db->where('afmeldtijd','00:00:00');
$data = $this->db->get();
return $data->result(); 
}   

控制器

public function count_ex()
{
$data['count_ex']  = $this->person->aantal_externe_today();
$this->load->view('my_view',$data);
}   

视图

<td><center><h3><?= $count_ex[''] ?></h3></center></td> 

5 个答案:

答案 0 :(得分:0)

public function aantal_externe_today()
{
   return $this->db->where('afmeldtijd','00:00:00')->count_all_results('doel');
}

答案 1 :(得分:0)

应该是这样的代码:

模型

public function aantal_externe_today()
{
  $this->db->select_count('doel');
  $this->db->where('afmeldtijd','00:00:00');
  $data = $this->db->get();
  return array("result"=>$data->result(),"num_rows"=>$data->num_rows()); 
} 

控制器

public function count_ex()
{
  $data['count_ex']  = $this->person->aantal_externe_today();
  $this->load->view('my_view',$data);
} 

视图

<td><center><h3><?= $count_ex['num_rows'] ?></h3></center></td> 

答案 2 :(得分:0)

你可以使用

$query->num_rows();

计算codeigntier中的所有行。

答案 3 :(得分:0)

我让这个工作

模态

public function aantal_externe_today()
{
$this->db->from($this->table);
    $this->db->where('afmeldtijd','00:00:00');
    return $this->db->count_all_results();
}

function kapjes()
{
    $this->db->select_sum('aantal');//standard codeigniter method for getting sum
$this->db->where('afmeldtijd','00:00:00');
    $t= $this->db->get()->row();
   return $t->aantal;//

}

public function aantal_externe_besloten()
{
$this->db->from($this->table);
    $this->db->where('afmeldtijd','00:00:00');
    $this->db->where('doel','2');
    return $this->db->count_all_results();
}

public function aantal_externe_gondel()
{
$this->db->from($this->table);
    $this->db->where('afmeldtijd','00:00:00');
    $this->db->where('doel','3');
    return $this->db->count_all_results();
}

控制器

public function index()
{
    $this->load->helper('url');
    $data['aan'] = $this->person->aantal_externe_today();
    $data['brand'] = $this->person->kapjes();
    $data['besloten'] = $this->person->aantal_externe_besloten();
    $data['gondel'] = $this->person->aantal_externe_gondel();
    $this->load->view('nav_view',$data);
    $this->load->view('person_view');
    $this->load->view('footer');

视图

<td></td>
<td></td>
<td></td>
<td><center><h3><?php echo $aan;?></h3></center></td> 
    <td></td>
<td><center><h3><?php echo $besloten;?></h3></center></td> 
    <td></td> 
<td><center><h3><?php echo $brand;?></h3></center></td> 

    <td></td> 
<td><center><h3><?php echo $gondel;?></h3></center></td>  
<td></td>
<td></td>
<td></td>
<td></td>

答案 4 :(得分:0)

使用活动记录类计算记录数的最佳方法

第一步:

$query = $this->db->select("id")->get("tablename");
echo $query->num_rows();

步骤 2:

echo $this->db->count_all('my_table');