我需要创建具有总数,平均值和中位数的表。现在我创建了总数和平均数。我的问题是如何找到中位数?我会动态地检索我的值到表。 这是我的编码,每个数据都在变量$ result和$ result1。
<table class="footable">
<thead>
<tr>
<th data-class="expand" data-sort-initial="true" style="text-align:center;" >State</th>
<th style="text-align:center;" >Final FY2010-11 Budget</th>
<th data-class="expand" data-type="numeric" style="text-align:center;" >Provisional FY2011-12 Budget</th>
<th data-class="expand" data-type="numeric" style="text-align:center;" >% Change</th>
</tr>
</thead>
<tbody>
<?php
for($i=0;$i<count($result);$i++) {
$this->actual_total += $result[$i]->breakdown_grants;
$this->provisional_total += $result1[$i]->breakdown_grants;
$this->actual_avg = $this->actual_total/count($result);
$this->provisional_avg = $this->provisional_total/count($result1);
$this->change = ($result[$i]->breakdown_grants + $result1[$i]->breakdown_grants)/100;
$this->total_change = ($this->actual_total + $this->provisional_total )/100;
$this->avg_change = ($this->actual_avg + $this->provisional_avg )/100;
?>
<tr>
<td style="text-align:center;" >
<span><?php echo $result[$i]->state; ?></span>
</td>
<td style="text-align:center;" >
<span><?php echo $result[$i]->breakdown_grants; ?></span>
</td>
<td style="text-align:center;" >
<span><?php echo $result1[$i]->breakdown_grants; ?></span>
</td>
<td style="text-align:center;" >
<span><?php echo $this->change." %" ; ?></span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<br/>
<table class="new">
<thead>
<tr>
<th></th>
<th style="text-align:center;">Final FY2010-11 Budget</th>
<th style="text-align:center;">Provisional FY2011-12 Budget</th>
<th style="text-align:center;">% Change</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;" >
<span>TOTAL</span>
</td>
<td style="text-align:center;">
<span><?php echo $this->actual_total; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->provisional_total; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->total_change." %" ; ?></span>
</td>
</tr>
<tr>
<td style="text-align:center;">
<span>AVERAGE</span>
</td>
<td style="text-align:center;">
<span><?php echo $this->actual_avg; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->provisional_avg; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->avg_change." %" ; ?></span>
</td>
</tr>
<tr>
<td style="text-align:center;">
<span>MEDIAN</span>
</td>
<td style="text-align:center;">
<span><?php echo $this->actual_avg; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->provisional_avg; ?></span>
</td>
<td style="text-align:center;">
<span><?php echo $this->avg_change." %" ; ?></span>
</td>
</tr>
</tbody>
</table>
这是我的模型编码
function reports_details1() {
$this->db->select('budget_breakdown.breakdown_grants');//survey_respondent_info.state,survey_respondent_info.survey_id,budgets.budget_id,
$this->db->from('survey_respondent_info');
$this->db->join('budgets', 'budgets.survey_id=survey_respondent_info.survey_id' , 'left');
$this->db->join('budget_breakdown', 'budgets.budget_id=budget_breakdown.budget_id' , 'left');
$this->db->where('budgets.budget_option_id', 2);
$query1 = $this->db->get();
$result = $query1->result();
return $result;
}