form_responses did join users table
This commit is contained in:
parent
ac5bc10376
commit
1f3d8d3848
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Response ID</th>
|
||||
<th>User Name</th>
|
||||
<th>Submitted At</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -14,8 +15,9 @@
|
|||
<?php if (!empty($responses)) : ?>
|
||||
<?php foreach ($responses as $response) : ?>
|
||||
<tr>
|
||||
<td><a href="<?= base_url('forms/view_response/' . $response->response_id) ?>"><?= $response->response_id ?></a></td>
|
||||
<td><?= date('Y-m-d H:i:s', strtotime($response->created_at)) ?></td>
|
||||
<td><?= $response->response_id ?></td>
|
||||
<td><a href="<?= base_url('forms/view_response/' . $response->response_id) ?>"><?= $response->username ?></a></td>
|
||||
<td><?= date('Y-m-d H:i:s', strtotime($response->submitted_at)) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
Response ID: <?= $response->response_id ?>
|
||||
</div>
|
||||
<div class="form_container_top_user-details">
|
||||
Submitted At: <?= date('Y-m-d H:i:s', strtotime($response->created_at)) ?>
|
||||
Submitted At: <?= date('Y-m-d H:i:s', strtotime($response->submitted_at)) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue