如何在活动记录中转换此代码:
$last_points = mysql_insert_id();
$sql = "SELECT COUNT(fkmember) FROM downline WHERE fkmember = {$last_points}";
$this->db->select('COUNT(fkmember)');
$query = $this->db->get_where('downline', array('fkmember'=> $last_points))->num_rows();
首先,在使用 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
$last_points = mysql_insert_id();
$count = $this->db->where('fkmember',$last_points)->get('downline')->num_rows();
$count 给出结果的计数