как правильно написать query чтобы я мог юзать дополнительные таблицы PHP: <?php class StudentModel { private $db; public function __construct(){ $this->db = new Database; } public function getStudents(){ $this->db->query('SELECT * FROM students'); $results = $this->db->resultSet(); return $results; } public function getStudentById( $student_id ){ $this->db->query('SELECT * FROM students WHERE student_id = :student_id'); $this->db->bind(':student_id', $student_id ); $row = $this->db->single(); return $row; } public function createStudent( $data ){ $this->db->query('INSERT INTO students (student_name,student_phone,student_email,student_image) VALUES(:student_name,:student_phone,:student_email,:student_image)'); // Bind values $this->db->bind(':student_name', $data['student_name']); $this->db->bind(':student_phone', $data['student_phone']); $this->db->bind(':student_email', $data['student_email']); $this->db->bind(':student_image', $data['student_image']); // Execute if($this->db->execute()){ return true; } else{ return false; } } public function updateStudent($data){ $this->db->query('UPDATE students SET student_name = :student_name, student_email = :student_email, student_phone = :student_phone, student_image = :student_image WHERE student_id = :student_id'); // Bind Values $this->db->bind(':student_id', $data['student_id']); $this->db->bind(':student_name', $data['student_name']); $this->db->bind(':student_email', $data['student_email']); $this->db->bind(':student_phone', $data['student_phone']); $this->db->bind(':student_image', $data['student_image']); // Execute if($this->db->execute()){ return true; } else{ return false; } } public function delete($data){ $this->db->query('DELETE FROM students WHERE student_id = :student_id'); // Bind values $this->db->bind(':student_id', $data['student_id']); // Execute if($this->db->execute()){ return true; } else{ return false; } } public function courses( $student_id ) { $select = "SELECT courses.* FROM courses LEFT JOIN courses_students ON courses.course_id = courses_students.course_id WHERE courses_students.student_id=:student_id"; $this->db->query( $select ); $this->db->bind(':student_id', $student_id ); $results = $this->db->resultSet(); return $results; } } --- Добавлено --- HTML: <div class="row"> <div class="sm-12 col"> <h2>New Student</h2> <p>Add new student to school</p> <form action="<?php echo URLROOT;?>/student/create" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="student_name">Student Name: <sup>*</sup></label> <input type="text" class="form-control form-control-lg <?php echo (!empty($data['errors']['name_err'])) ? 'is-invalid':'';?>" name="student_name" value="<?php echo $data['errors']['student_name'];?>"> <span class="invalid-feedback"><?php echo $data['errors']['name_err']; ?></span> </div> <div class="form-group"> <label for="student_email">Student Email: <sup>*</sup></label> <input type="email" class="form-control form-control-lg <?php echo (!empty( $data['errors']['email_err'])) ? 'is-invalid':'';?>" name="student_email" value="<?php echo $data['errors']['student_email']; ?>"> <span class="invalid-feedback"><?php echo $data['errors']['email_err']; ?></span> </div> <div class="form-group"> <label for="student_phone">Student Phone: <sup>*</sup></label> <input type="text" class="form-control form-control-lg <?php echo (!empty( $data['errors']['email_err'])) ? 'is-invalid':'';?>" name="student_phone" value="<?php echo $data['errors']['student_phone']; ?>"> <span class="invalid-feedback"><?php echo $data['errors']['phone_err']; ?></span> </div> <div class="form-group"> <label for="student_image">Student Photo: <sup>*</sup></label> <input type="file" class="form-control-file form-control-lg <?php echo (!empty( $data['errors']['img_err'] )) ? 'is-invalid':'';?>" name="student_image" value="<?php echo $data['errors']['student_image'];?>"> <span class="invalid-feedback"><?php echo $data['errors']['img_err']; ?></span> </div> <div class="form-group"> <ul> <?php foreach ($data['courses'] as $course ) { ?> <li> <input type="checkbox" name="courses[]" class="form-check-input"> <label for="courses[]" class="form-check-label"><?php echo $course->course_name; ?></label> </li> <?php }; ?> </ul> </div> <div class="form-group"> <input type="submit" value="Add Student" class="btn btn-success btn-block"> </form> </div> </div> оутпут --- Добавлено --- контролер PHP: <?php class Student extends Controller{ public function __construct(){ if(!isLoggedIn()){ redirect('pages/login'); } $this->StudentModel = $this->model('StudentModel'); $this->CourseModel = $this->model('CourseModel'); } public function index( $extra = null, $template = null ){ $students = $this->StudentModel->getStudents(); $courses = $this->CourseModel->getCourses(); $data = [ 'title' => 'Welcome to School', 'courses' => $courses, 'students' => $students ]; if (!empty($extra)) { $keys = array_keys($extra); $data[$keys[0]] = $extra[$keys[0]]; } if (!empty($template)) { $data[ 'student_template' ] = $template; } $this->view('school/index', $data ); } public function create(){ if($_SERVER['REQUEST_METHOD'] == 'POST'){ $_POST = filter_input_array(INPUT_POST); $data = [ 'student_name' => trim($_POST['student_name']), 'student_email' => trim($_POST['student_email']), 'student_phone' => trim($_POST['student_phone']), 'student_image' => trim($_POST['student_image']), 'name_err' => '', 'email_err' => '', 'image_err' => '' ]; // Validate Data if(empty($data['student_name'])){ $data['name_err'] = 'Please enter student name'; } if(empty($data['student_email'])){ $data['email_err'] = 'Please enter student email address'; } if(empty($data['student_phone'])){ $data['phone_err'] = 'Please enter phone number'; } // if(empty($data['student_image'])){ // $data['img_err'] = 'Please enter student photo'; // } // Make sure no errors if(empty($data['name_err']) && empty($data['email_err']) && empty($data['img_err'])){ // Validated if( $this->StudentModel->createStudent($data) ){ flash('student_message', 'Student added'); redirect('school'); } else{ die('Something went wrong'); } } else { // Load view with errors $this->index( array( 'errors' => $data ), 'create' ); } } else { $data = [ 'student_name' => '', 'student_email' => '', 'student_phone' => '', 'student_image' => '' ]; $this->index( array( 'errors' => $data ), 'create' ); } } public function display( $id){ $student = $this->StudentModel->getStudentById( $id ); $courses = $this->StudentModel->courses( $id ); $info['student'] = $student; $info['courses'] = $courses; $this->index( array( 'info' => $info ), 'display' ); } public function delete ( $id ) { if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) { // Get existing student from model $this->StudentModel->getStudentById ( $id ); // Check for owner // Removing Post if ( $this->StudentModel->delete ( $id ) ) { flash ( 'student_message' , 'Student Removed' ); redirect ( 'school' ); } else { die( 'Something went wrong' ); } } else { redirect ( 'posts' ); } } } --- Добавлено --- есть еще такое же на курс