如果我从数据库中选择一个下拉值,那么应该显示标题值,例如我从下拉列表中选择关于我们页面,之后应该显示标题值帮助我任何一个
查看页面
<form class="form-horizontal" action="#" method="POST">
<?php foreach ($seo_tag_update as $rows) { ?>
<div class="form-group">
<label class="col-sm-4 control-label">Select Pages:</label>
<div class="col-sm-6">
<select class="form-control" name="select_update_page" id="select_update_page">
<option value=""> -- select pages -- </option>
<?php
echo '<option value="' . $rows->page_id . '">' . $rows->page_name . '</option>';
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Title:</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="update_title" id="update_title " value="<?php echo $rows->page_title; ?>">
</div>
</div>
</div><?php } ?>
<div class="form-group">
<div class="col-md-offset-4 col-sm-6">
<button class="btn btn-sumit">SUBMIT</button>
</div>
</div>
</form>
控制器
public function update() {
$this->load->helper('url');
$data['seo_tag_update'] = $this->Question_Insertion_Model->seo_tag_Update();
echo "$posted_id";
$this->load->view('update', $data);
}
型号
public function seo_tag_Update() {
$this->db->select('*');
$this->db->from('kas_all_pages s');
$this->db->join('kas_all_pages_tags q','s.page_id=q.page_fk');
$this->db->where('s.page_id', 1);
$query = $this->db->get();
return $result = $query->result();
}
答案 0 :(得分:1)
问题是您正在循环并创建多个<select>
(和<input>
)元素,而不是创建元素并仅生成<option>
元素。
<form class="form-horizontal" action="#" method="POST">
<!-- CREATE SELECT ELEMENT -->
<div class="form-group">
<label class="col-sm-4 control-label">Select Pages:</label>
<div class="col-sm-6">
<select class="form-control" name="select_update_page" id="select_update_page">
<option value=""> -- select pages -- </option>
<!-- ADD OPTIONS TO DROPDOWN -->
<?php
foreach ($seo_tag_update as $rows) {
echo '<option value="' . $rows->page_id . '">' . $rows->page_name . '</option>';
}
?>
<!-- CLOSE SELECT ELEMENT -->
</select>
</div>
</div>
<!-- CREATE TITLE ELEMENT -->
<div class="form-group">
<label class="col-sm-4 control-label">Title:</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="update_title" id="update_title " value="">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-sm-6">
<button class="btn btn-sumit">SUBMIT</button>
</div>
</div>
</form>
然后你需要一些JavaScript来更新变更值。有很多方法可以在“vanilla”JavaScript中执行此操作,或者如果您已经包含jQuery,则可以查看.change()
函数(docs)。