【发布时间】:2018-08-06 05:19:49
【问题描述】:
我想在数据库的视图中显示问题及其各自的答案:
我得到了名为Feedback的数据库表,格式如下:
这是我的表格名称:反馈
id | employee_id | question_id | answer |
______________________________________________________
1 | 100 | 1 | That was awesome.
2 | 100 | 2 | That was excellent.
3 | 100 | 3 | That was good.
4 | 101 | 1 | That was better.
5 | 101 | 2 | That was interesting.
6 | 101 | 3 | That was fine.
还有另一个以问题命名的表格:
id | Question |
_______________________________________________
1 | How was your day?
2 | How was the task?
3 | How was the Project?
这是我的模型代码:
function get_answers_supervisee () {
$userid = $this->session->userdata('userid');
$result = array ();
$sql = "select answer from Feedback where employee_id = '$userid'";
$query = $this->db->query ( $sql );
foreach ( $query->result_array () as $row ) {
array_push ( $result, $row );
}
return $result;
}
下面是我的表单(客户端视图):
<table class="table">
<?php foreach($form_data_supervisee as $question) {?>
<tr>
<td>
<?php echo $question['ID'].". ".$question['DESCRIPTION']?>
</td>
</tr>
<?php foreach($form_answers_supervisee as $answer) {?>
<tr>
<td>
<textarea rows="5" name="<?php echo $answer['ANSWER']?></textarea>
</td>
</tr>
<?php } ?>
<?php }?>
</table>
这是我的控制器的一部分:
$data['form_answers_supervisee'] = $this->appraisal_model->get_answers_supervisee();
$data['form_answers_supervisor'] = $this->appraisal_model->get_answers_supervisor();
$this->load->view('main_form',$data);
现在,对于具有 employee_id: 100
的员工,我得到以下输出1. How was your day?
That was awesome.
That was excellent.
That was good.
2. How was the task?
That was awesome.
That was excellent.
That was good.
3. How was the Project?
That was awesome.
That was excellent.
That was good.
所需的输出应该是:
1. How was your day?
That was awesome.
2. How was the task?
That was excellent.
3. How was the Project?
That was good.
我需要在这里进行什么更正?我做错了什么?
非常感谢您的建议。
【问题讨论】:
-
我刚刚将问题和从评估商店命名的表格更新为反馈。我想以简单的形式提问,所以不得不更改有问题的数据库内容和表名,而忘记更改问题中的表名。
标签: php codeigniter codeigniter-3 codeigniter-query-builder