我想为我创建的每个活动计算学生表中具有相同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);
}
答案 0 :(得分:0)
//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);
}