暗示 在代码点火器中选择计数并回显结果



我想在CodeIgniter中实现以下查询:

SELECT COUNT(*) FROM tickets WHERE status = "open";

返回的结果将是"1",我想回应结果。我有当前的代码查询:

$this->db->count_all_results();
$this->db->select('*');
$this->db->where('status', 'Open');
$this->data['opentickets'] = $this->support_m->get();

我正在尝试在视图中显示计数结果。关于我该如何做到这一点的任何建议?

请尝试以下代码以获取具有打开状态的行数。

$this->db->where("status", 'Open');
$query = $this->db->get("tickets");
$this->data['opentickets'] = $query->num_rows();

或者你可以使用这个

$sql = 'SELECT COUNT(*) FROM tickets WHERE status = "open"';
$query = $this->db->query($sql);
$this->data['opentickets'] =  $query->row_array()['COUNT(*)'];

您可以在代码点火器中运行查询:

$sql = 'SELECT COUNT(*) FROM tickets WHERE status = "open"';
$query = $this->db->query($sql);
$this->data['opentickets'] = $query->result_array();

相关内容

  • 没有找到相关文章

最新更新