From 1f3d8d3848e616b100130b0ad7341277916f827c Mon Sep 17 00:00:00 2001 From: jostheta Date: Tue, 23 Jul 2024 13:11:51 +0530 Subject: [PATCH] form_responses did join users table --- application/controllers/Forms.php | 3 +++ application/models/Form_model.php | 11 +++++++---- application/views/forms/form_responses.php | 6 ++++-- application/views/forms/view_response.php | 2 +- assets/js/script.js | 11 ----------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index f8120ea..6c53cf7 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -290,6 +290,9 @@ class Forms extends CI_Controller $user_id = $this->session->userdata('user_id'); $data['responses'] = $this->Form_model->get_responses_by_form($form_id); $data['form'] = $this->Form_model->get_form($form_id); + $responses = $this->Form_model->get_responses_by_form($form_id); + + $this->load->view('templates/header'); $this->load->view('forms/form_responses', $data); diff --git a/application/models/Form_model.php b/application/models/Form_model.php index 9a32dcd..3b2d826 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -138,7 +138,7 @@ class Form_model extends CI_Model { $response_data = [ 'form_id' => $form_id, 'user_id' => $this->session->userdata('user_id'), // Set user_id if applicable - 'created_at' => date('Y-m-d H:i:s'), + 'submitted_at' => date('Y-m-d H:i:s'), ]; $this->db->insert('responses', $response_data); $response_id = $this->db->insert_id(); @@ -176,13 +176,16 @@ class Form_model extends CI_Model { $query = $this->db->get('forms'); return $query->result(); } - public function get_responses_by_form($form_id) { - $this->db->where('form_id', $form_id); - $query = $this->db->get('responses'); + $this->db->select('responses.user_id, users.username, responses.submitted_at,responses.response_id'); + $this->db->from('responses'); + $this->db->join('users', 'responses.user_id = users.user_id'); + $this->db->where('responses.form_id', $form_id); + $query = $this->db->get(); return $query->result(); } + public function get_response($response_id) { $this->db->where('response_id', $response_id); $query = $this->db->get('responses'); diff --git a/application/views/forms/form_responses.php b/application/views/forms/form_responses.php index 156cc43..480fb92 100644 --- a/application/views/forms/form_responses.php +++ b/application/views/forms/form_responses.php @@ -7,6 +7,7 @@ Response ID + User Name Submitted At @@ -14,8 +15,9 @@ - response_id ?> - created_at)) ?> + response_id ?> + username ?> + submitted_at)) ?> diff --git a/application/views/forms/view_response.php b/application/views/forms/view_response.php index 92ecb17..3326325 100644 --- a/application/views/forms/view_response.php +++ b/application/views/forms/view_response.php @@ -15,7 +15,7 @@ Response ID: response_id ?>
- Submitted At: created_at)) ?> + Submitted At: submitted_at)) ?>
diff --git a/assets/js/script.js b/assets/js/script.js index 73fa058..10016a1 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -115,17 +115,6 @@ $(document).ready(function() { // Add active class to the clicked question box questionBox.addClass('active'); - // Scroll sidebar to the active question - var offset = questionBox.offset().top - $('.sidebar').offset().top; - console.log(questionBox.offset().top,'question'); - console.log($('.sidebar').offset().top,'sidebar'); - console.log(offset,'offset'); - console.log(offset + $('.sidebar').scrollTop(),'offset plus sidebar'); - - $('.sidebar').animate({ - scrollTop: offset + $('.sidebar').scrollTop() - }, 500); - } // Add click event listener to all question boxes to set active question