[英]counting the results in codeigniter
我想為我創建的每個活動計算學生表中具有相同eventId的表中的所有結果。 這是我數據庫中兩個表的摘要。 活動和學生參加者表。
studentattendees
表:
activity
表:
我想知道如何制作一個模型函數來計算所有結果,其中學生參加者中的eventId等於活動表中的activityId。 另外,我將如何回應這一觀點。 這是我在模型,視圖,控制器中的代碼示例。
//view
public function getReportAttendees(){
$this->db->order_by('activity.activityId', 'DESC');
$query = $this->db->get('activity');
// date status
$resulting = $query->result_array();
foreach($resulting as $resultings){
$activity = $resultings['activityId'];
$this->db->join('activity', 'activity.activityId =
studentattendees.eventId');
$this->db->where('eventId',$activity);
$this->db->from('studentattendees');
$count = $this->db->count_all_results();
foreach($count as $counts){
array_push($countall, $count);
}
}
return $countall;
}
//view
<?php
if($attendee){
foreach($attendee as $attendees){
?>
<td><?php echo $attendees; ?></td>
<?php
}
}
?>
//controller
public function ReportGenerated(){
$data['attendee'] = $this->u->getReportAttendees();
$this->load->view('logmanagement/reportgenerated', $data);
}
//modal
public function getReportAttendees(){
$countall = array();
$this->db->order_by('activity.activityId', 'DESC');
$query = $this->db->get('activity');
$resulting = $query->result_array();
foreach($resulting as $resultings){
$activity = $resultings['activityId'];
$this->db->join('activity', 'activity.activityId = studentattendees.eventId');
$this->db->where('eventId',$activity);
$this->db->from('studentattendees');
$count = $this->db->count_all_results();
foreach($count as $counts){
array_push($countall, $count);
}
}
return $countall;
}
//view
<?php
if($attendee){
foreach($attendee as $attendees){
?>
<td><?php echo $attendees; ?></td>
<?php
}
}
?>
//controller
public function ReportGenerated(){
$data['attendee'] = $this->u->getReportAttendees();
$this->load->view('logmanagement/reportgenerated', $data);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.