代码点火器增量



所以我有这个函数来获取表中的总行数。

这是我的代码:

public function get_reservation()
{
$this->db->select('COUNT(*) as res_no ');
$this->db->from('reservation_details');
$query = $this->db->get()->result();
echo json_encode($query);
}

它返回此JSON 数据

[{"res_no":"2"}]

我想要的是将其值增加到 1 并像这样返回

[{"res_no":"3"}]

到目前为止,我已经尝试过这样的事情

这是我的代码:

public function get_reservation()
{
$query = $this->db->select('COUNT(*) as res_no ')->from('reservation_details')->get();
$price =  $query->row()->res_no;
$price = $price + 1;
echo json_encode($price);
} 

但它只会返回3

希望这会对您有所帮助:

使用 CI 查询帮助程序count_all对表的所有记录进行计数

public function get_reservation()
{
$count = $this->db->count_all('reservation_details');
$price = $count + 1;
$data['res_no'] = $price;
echo json_encode($data);
} 

获取更多 : https://www.codeigniter.com/userguide3/database/helpers.html#information-about-your-database

最新更新