-1

如何在活动记录中转换此代码:

$last_points = mysql_insert_id(); 
$sql = "SELECT COUNT(fkmember) FROM downline WHERE fkmember = {$last_points}"; 
4

3 回答 3

4
$this->db->select('COUNT(fkmember)');
$query = $this->db->get_where('downline', array('fkmember'=> $last_points))->num_rows();
于 2012-09-27T05:08:50.180 回答
2

首先,在使用 COUNT 这样的聚合函数时,建议使用 GROUP BY

$last_points = $this->db->insert_id();

$this->db->from('downline');
$this->db->where('fkmember', $last_points);
$this->db->group_by('fkmember');
echo $this->db->count_all_results();
// Produce an integer, like 17

您也可以参考手册:http ://codeigniter.com/user_guide/database/active_record.html

于 2012-09-27T05:16:16.047 回答
0
$last_points = mysql_insert_id(); 

$count = $this->db->where('fkmember',$last_points)->get('downline')->num_rows();

$count 给出结果的计数

于 2012-09-27T10:44:50.107 回答