【发布时间】:2021-11-14 23:13:46
【问题描述】:
我有 2 个表 tbl_office 和 tbl_result
| id | office_name | | id | office | rating | comment |
|----|-------------| |----|-------------|-----------|---------|
| 1 | Records | | 1 | Records | Satisfied | |
| 2 | Logistics | | 2 | Logistics | Satisfied | |
| 3 | HR | | 3 | HR | Neutral | |
我在我的表单上使用了 SELECT OPTION 标签来从 tbl_office
获取 office_name 的行值控制器
namespace App\Controllers;
use App\Models\SurveyModel;
use App\Models\OfficeMOdel;
class Survey extends BaseController
{
public function index()
{
$data = [];
helper(['form','url']);
$office = new OfficeMOdel();
$data['office'] = $office->findAll();
if($this->request->getMethod() == 'post'){
$rules = [
'office' => ['label' => 'Office', 'rules' => 'required'],
'rating' => ['label' => 'Rating', 'rules' => 'required']
];
if (!$this->validate($rules)){
$data['validation'] = $this->validator;
}else{
$model = new SurveyModel();
$newData = [
'office' => $this->request->getVar('office'),
'rating' => $this->request->getVar('rating'),
'comment' => $this->request->getVar('comment'),
];
$model->save($newData);
$session = session();
$session->setFlashdata('success','Your Feedback has been successfully added to our system!',);
return redirect()->to('survey/confirmation');
}
}
echo view ('templates/header_form', $data);
echo view ('surveyform');
echo view ('templates/footer_form');
}
PHP/HTML 用于显示 office_name
的值<select name="office">
<?php foreach($office as $row) :?>
<option><?php echo $row['office_name'] ?></option>
<?php endforeach; ?>
</select>
IT WORKS,但是当我从 tbl_office 更新 from office_name 的值时,tbl_result 上的值不改变。当我将选项插入另一个表时,有没有办法链接这些值而不是仅仅获取选项的值?
非常感谢您的回答。这里是初学者。
【问题讨论】:
标签: javascript php mysql codeigniter-4