在选定的选项中显示数据



伙计们,需要帮助。我现在正在使用codeigniter处理我的投资组合,我对编辑表单modal很感兴趣,因为我想显示选项是用mysql中的数据选择的,但它没有

这是我的控制器:

控制器

这是我的型号:

<?php

class User_model extends CI_Model {

function session_user_info($session_user){
function get_multi_item_data_inserted($session_ref_id){
$output = '';

$this->db->select('*');
$this->db->from('incident_cat');
$q_storeCode = $this->db->get();
$incident = $q_storeCode->result();

$this->db->select('*');
$this->db->from('store_code');
$q_storeCode = $this->db->get();
$store_code = $q_storeCode->result();

$this->db->select('*');
$this->db->order_by('ref_id','DESC');
$this->db->join('incident_cat','item_details.incident_type = incident_cat.incident_id');
$this->db->join('store_code','item_details.store_code = store_code.store_id');
$this->db->where('ref_id_num', $session_ref_id);
$this->db->from('item_details');
$get_query = $this->db->get();
$output .= '<table class="table table-striped table-responsive">
<thead class="bg-primary">
<th class="text-center">Store</th>
<th class="text-center">Action</th>
</thead>
<tbody>';
if($get_query->num_rows() > 0){
foreach ($get_query->result() as $row):
$output .= '<tr>
<td class="text-center">'.$row->store_area.'</td>
<td class="text-center">'.'
<a href="#editItemDataForm'.$row->ref_id.'" data-toggle="modal" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span>
</a>
<button onClick="del_Data('.$row->ref_id.')" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span>
</button>
'.'</td>
</tr>';
$output .= '<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModal" id="editItemDataForm'.$row->ref_id.'" aria-hidden="true">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header bg-primary">
<button type="button" class="close" data-dismiss="modal" id="close_btn">&times;</button>
<h5 class="modal-title"><span class="fa fa-pencil"></span> <b>Edit item(s) </b></h5>
</div>
<div class="modal-body">
<form method="post" class="form-vertical addform">
<div class="form-group">
<div id="edit_store_code_err">
<label for="store_code">* Store code:</label>
<select type="text" name="edit_store_code" id="edit_store_code" class="form-control input-sm">
<option value="">--- Select store code---</option>

';

//我在这里有存货//

foreach ($store_code as $rows){
$output .= '<option value="'.$rows->store_id.'"'.if($rows->store_id == $row->store_code)."selected".'>'.$rows->description.' - '.$rows->code.'
</option>';

/*if($rows->store_id == $row->store_code){
$output .= '<option value="'.$rows->store_id.'" selected>'.$rows->description.' - '.$rows->code.'
</option>';
}*/
}
$output .= '</select>
<p class="text-danger" id="edit_store_code_error_msg"></p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>';
endforeach;
}else{
$output .= '<tr>
<td class="text-center text-danger" colspan="6"><b> ***** Table is empty ***** </b></td>
</tr>';
}
$output .= '</tbody>
</table>';

return $output;
}
?>

请帮帮伙计们。

提前感谢各位。

显示输出

而不是这个-

$output .= '<option value="'.$rows->store_id.'"'.if($rows->store_id == $row->store_code)."selected".'>'.$rows->description.' - '.$rows->code.' </option>';

你应该以以下方式使用它-

$selected = ($rows->store_id == $row->store_code) ? 'selected' : '';
$output .= '<option value="'.$rows->store_id.'" '.$selected.' >'.$rows->description.' - '.$rows->code.'</option>';

它将首先根据条件设置selected属性,然后将其分配给选择选项。

相关内容

  • 没有找到相关文章

最新更新