我想在codeigniter中获取数据结果

时间:2018-02-14 07:48:04

标签: php mysql codeigniter

我的查询有问题

目前得到的结果是:

Array ( [0] => stdClass Object ( [( SELECT total_available FROM sms WHERE clinic_id = 1 ) - COUNT( sms_history.clinic_id)] => 494 ) )

我想:494

我的表:

sms_history表 短信表 用户表

我的代码:

控制器:

 $total_available = $this->Dashboard_m->get_total_available_sms();
 print_r($total_available);

型号:

public function get_total_available_sms()
{

$query = $this->db->query('SELECT ( SELECT total_available FROM sms WHERE clinic_id = 1 ) - COUNT( sms_history.clinic_id) FROM sms_history JOIN sms ON sms_history.clinic_id= sms.clinic_id');

return $query->result(); 

}

1 个答案:

答案 0 :(得分:0)

使用此查询:SELECT (( SELECT total_available FROM sms WHERE clinic_id = 1 ) - COUNT( sms_history.clinic_id)) AS num FROM sms_history JOIN sms ON sms_history.clinic_id= sms.clinic_id

因此,您可以使用' num'指数。 您可以使用result()或result_array()函数并使用' num'索引相应。谢谢。