function view($id) { $model = new Student(); $act = new Activities_student(); $student = $model->select($id); $act->where("id", $id); $activity = $act->query("SELECT point from activitys\n LEFT JOIN activities_students ON activitys.id = activities_students.activity_id\n WHERE student_id = {$id}"); $this->set('student', $student); $this->set('info', $activity); }
/** * @param $section * @param $num * @param string $string */ private function bestIn($section, $num, $string = "YEAR") { $st_activity = new Activities_student(); $students = $st_activity->query("SELECT first_name,last_name, f_number, sum(point) point FROM activities_students\n LEFT JOIN activitys ON activities_students.activity_id = activitys.id\n LEFT JOIN students ON activities_students.student_id = students.id\nWHERE created_at > DATE_SUB(NOW(), INTERVAL 1 " . "{$string}" . ") AND `{$section}` = {$num}\nGROUP BY student_id\nORDER BY point DESC"); $result = array(); $i = 0; foreach ($students as $key => $student) { $st = $student['Student']['first_name'] . " " . $student['Student']['last_name']; $pt = $student['']['point']; array_push($result, array($st => $pt)); } if (!empty($result)) { foreach ($result as $name => $point) { foreach ($point as $key => $value) { echo "<br>"; echo ++$i . ". " . $key . " - " . $value . " points."; echo "<br>"; } } } else { echo "<br>No active students!"; } }