[eluser]CI_Newb[/eluser]
What I want to do is get a "top 10 agents" list. This would be easy but what I want to do is have it for agents with a TOTAL over 10.
I have the count as total in there, but can't figure out how to exclude anyone with a TOTAL under 10.
Model
Code:
function get_top_agents()
{
$this->db->select('agent_id');
$this->db->select('COUNT(agent_id) AS TOTAL');
$this->db->select('(AVG(Q1)+ AVG(Q2_1)+ AVG(Q2_2)+ AVG(Q2_3)+ AVG(Q2_4)+ AVG(Q2_5)+ AVG(Q3)) / 7 AS AGENT_AVG');
$this->db->where('completed', '1');
$this->db->like('submit_date', YEAR_MONTH);
$this->db->group_by("agent_id");
$this->db->order_by("AGENT_AVG", "desc");
//$this->db->limit(10);
$data = $this->db->get('survey');
return $data;
}
View
Code:
<?php foreach (@$top_agents->result() as $row):
@$count++;
if(($count % 2) == 1){
$class = "row0";
} else {
$class = "row1";
}
?>
<tr>
<td align="left"><b><?php echo $row->ns_agent_id; ?></b></td>
<td align="center"><?php echo $row->TOTAL; ?></td>
<td align="center"><?php echo round($row->AGENT_AVG, 2); ?></td>
<td></td>
</tr>
<?php endforeach; ?>
Any help would be greatly appreciated
EDIT: Friend said I should clarify what i'm trying to accomplish a bit more.
This is invalid code, but basically what I want to accomplish
Code:
function get_top_agents()
{
$this->db->select('agent_id');
$this->db->select('COUNT(agent_id) AS TOTAL');
$this->db->select('(AVG(Q1)+ AVG(Q2_1)+ AVG(Q2_2)+ AVG(Q2_3)+ AVG(Q2_4)+ AVG(Q2_5)+ AVG(Q3)) / 7 AS AGENT_AVG');
$this->db->where('completed', '1');
$this->db->where('TOTAL >=', '10');
$this->db->like('submit_date', YEAR_MONTH);
$this->db->group_by("agent_id");
$this->db->order_by("AGENT_AVG", "desc");
$this->db->limit(10);
$data = $this->db->get('survey');
return $data;
}