見我有兩個表tbl_office和tbl_result
| id | office_name | id | office | rating | comment |
|----|-------------| |----|-------------|-----------|---------|
| 1 | 記錄 | | 1 | 記錄 | 滿意 | |
2 | 物流 | 2 | 物流 | 滿意 | |
3 | HR | 3 | HR | Neutral | |
我在表單中使用了一個SELECT OPTION標簽,從tbl_office中獲取office_name的行值。
CONTROLLER
namespace AppControllers。
使用 AppModelsSurveyModel。
use AppModelsOfficeMOdel;
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, but when I update the value from office_name from tbl_office, the value on the tbl_result does not change. 有什么方法可以將這些值聯系起來,而不是在我將其插入到另一個表中時只獲得選項的值?
非常感謝您的回答。我是初學者。
uj5u.com熱心網友回復:
在索引中連接兩個表
$result = $this-> model-> select('require_post.*')
->加入('users', 'request_reply.user_id = users.id', 'left')
->加入('request_post', 'request_reply.post_id = request_post.id', 'left')
->where(['request_post.id'=>['1']] )
->分頁(10, 'default',1, 0) 。
uj5u.com熱心網友回復:
你應該在你的tbl_result中存盤office名稱。相反,你應該存盤office_id:
CREATE TABLE `tbl_office` (
id int primary key auto_increment,
name varchar(64)
);
CREATE TABLE `tbl_rating` (
id int primary key auto_increment,
name varchar(64)
);
CREATE TABLE `tbl_result` (
id int primary key auto_increment,
office_id int,
rating_id int。
評論文本
);
SELECT `res`.`id`, `o`。 `name` AS `office`, `r``. `name` AS `rating`, `comment`.
FROM `tbl_result` `res`/span>
JOIN `tbl_office` `o` ON `o`. `id` = `res`.`office_id`。
JOIN `tbl_rating` `r` ON `r`。 `id` = `res`.`rating_id`.
==== =========== =========== ======== 。
| id | office | rating | comment|
==== =========== =========== ======== 。
| 1 | 記錄 |滿足 | (null) |
---- ----------- ----------- ---------
| 2 | 物流 |滿足 | (null) |
---- ----------- ----------- ---------
| 3 | HR|Neutral | (null) |
---- ----------- ----------- ---------
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/332008.html
標籤:
