我正在控制器中使用添加和编辑表单,如图所示。
function get_master() {
$store_id = $this->input->post('store_id');
$get_store = $this->common->get_row(array(
'store_id' => $store_id
), DBPREFIX . "store");
$store = $get_store->store_state_id;
$company = $get_store->store_company_id;
$this->session->set_userdata('store', $store);
$this->session->set_userdata('company', $company);
$data['master'] = $master = $this->common->get_whereresult(DBPREFIX . 'apimaster', array('master_status' => 1, 'master_state' => $store), 'master_name');
$tbody = '';
foreach ($master as $store_products) {
$config = $this->common->get_whereresult(DBPREFIX . 'metrcsetting_conf', array('metrcsettingconf_status' => 1, 'metrcsettingconf_master_id' => $store_products->master_id, 'metrcsettingconf_company_id' => $company, 'metrcsettingconf_store_id' => $store_id));
$tbody .= '<div class="row">';
$tbody .= '<div class="form-group col-md-12 col-sm-12 col-xs-12">';
$tbody .= '<div class="panel panel-default">';
$tbody .= '<div class="panel-heading" role="tab" id="headingOne">';
$tbody .= '<h4 class="panel-title" style="height:18px;">';
$tbody .= '<form action="add_metrcsettingmaster/' . $store_products->master_id . '" method="post">';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12">';
$tbody .= '<a data-toggle="collapse" data-parent="#accordion" id="master_id" href="#collapseOne'. $store_products->master_id .'" aria-expanded="true" aria-controls="collapseOne'. $store_products->master_id .'">' . $store_products->master_name . '</a>';
$tbody .= '<input id="master_idd" type="hidden" value="' . $store_products->master_id . '">';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 start_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="">';
$tbody .= '<span class="start_datetext">Sync Active</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 end_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="End Date" id="jd" type="text" class="form-control hasDatepicker" name="end_date" value="">';
$tbody .= '<span class="end_datetext">Sync Expire</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12 time" style="margin-top:-5px;">';
$tbody .= '<input type="time" name="time" class="form-control" value="">';
$tbody .= '<span class="timetext">Sync Time</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12" style="margin-top: -5px">';
$tbody .= '<select name="days[]" class="form-control status chosen-select" multiple="multiple">';
$tbody .= '<option value="Monday">Monday</option>';
$tbody .= '<option value="Tuesday">Tuesday</option>';
$tbody .= '<option value="Wednesday">Wednesday</option>';
$tbody .= '<option value="Thursday">Thursday</option>';
$tbody .= '<option value="Friday">Friday</option>';
$tbody .= '<option value="Saturday">Saturday</option>';
$tbody .= '<option value="Sunday">Sunday</option>';
$tbody .= '</select>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12" style="margin-top:-8px;text-align:center;">';
$tbody .= '<label class="switch">';
$tbody .= '<p style="margin-top:10px;margin-left:-60px;"> Manual </p>';
$tbody .= '<p style="margin-top:-27px;margin-left:60px;"> Auto </p>';
$tbody .= '<input type="checkbox" name="manauto" id="chkPassportt" value="">';
$tbody .= '<span class="slider round"></span>';
//$tbody .= 'form_error('"manauto"');';
$tbody .= '</label>';
$tbody .= '</div>';
$tbody .= '<div class="col-md-2 col-lg-2 col-sm-2 col-xs-12 pull-right" style="margin-top:-8px;">';
$tbody .= '<input class="btn btn-danger" type="submit" name="submit" value="Submit">';
$tbody .= '</div>';
$tbody .= '</form>';
$tbody .= '</h4>';
$tbody .= '</div>';
$tbody .= '<div id="collapseOne'. $store_products->master_id .'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">';
$tbody .= '<div class="panel-body">';
$tbody .= '<div id="childdata">';
$master_id = $store_products->master_id;
$data['child'] = $child = $this->common->get_whereresult(DBPREFIX . 'apichild', array('child_status' => 1, 'child_master' => $master_id), 'child_apiname');
foreach ($child as $store_products) {
$tbody .= '<div class="row">';
$tbody .= '<div class="form-group col-md-12 col-sm-12 col-xs-12">';
$tbody .= '<div class="panel panel-default">';
$tbody .= '<div class="panel-heading" role="tab" id="headingOne">';
$tbody .= '<h4 class="panel-title" style="height:18px;">';
$tbody .= '<form action="add_metrcsettingchild/' . $store_products->child_id . '" method="post">';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12">';
$tbody .= '<a data-toggle="collapse" data-parent="#accordion" id="child_id" href="#collapseOne'. $store_products->child_id .'" aria-expanded="true" aria-controls="collapseOne'. $store_products->child_id .'">' . $store_products->child_apiname . '</a>';
$tbody .= '<input id="child_idd" type="hidden" value="' . $store_products->child_id . '">';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 start_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="">';
$tbody .= '<span class="start_datetext">Sync Active</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 end_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="End Date" id="jd" type="text" class="form-control hasDatepicker" name="end_date" value="">';
$tbody .= '<span class="end_datetext">Sync Expire</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12 time" style="margin-top:-5px;">';
$tbody .= '<input type="time" name="time">';
$tbody .= '<span class="timetext">Sync Time</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12" style="margin-top: -5px">';
$tbody .= '<select name="days[]" class="form-control status chosen-select" multiple="multiple">';
$tbody .= '<option value="Monday">Monday</option>';
$tbody .= '<option value="Tuesday">Tuesday</option>';
$tbody .= '<option value="Wednesday">Wednesday</option>';
$tbody .= '<option value="Thursday">Thursday</option>';
$tbody .= '<option value="Friday">Friday</option>';
$tbody .= '<option value="Saturday">Saturday</option>';
$tbody .= '<option value="Sunday">Sunday</option>';
$tbody .= '</select>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12" style="margin-top:-8px;text-align:center;">';
$tbody .= '<label class="switch">';
$tbody .= '<p style="margin-top:10px;margin-left:-60px;"> Manual </p>';
$tbody .= '<p style="margin-top:-27px;margin-left:60px;"> Auto </p>';
$tbody .= '<input type="checkbox" name="manauto" id="chkPassportt">';
$tbody .= '<span class="slider round"></span>';
//$tbody .= 'form_error('"manauto"');';
$tbody .= '</label>';
$tbody .= '</div>';
$tbody .= '<div class="col-md-2 col-lg-2 col-sm-2 col-xs-12 pull-right" style="margin-top:-8px;">';
$tbody .= '<input class="btn btn-danger" type="submit" name="submit" value="Submit">';
$tbody .= '</div>';
$tbody .= '</form>';
$tbody .= '</h4>';
$tbody .= '</div>';
$tbody .= '<div id="collapseOne'. $store_products->child_id .'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">';
$tbody .= '<div class="panel-body">';
$tbody .= '<div id="childdata"></div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
}
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
}
echo $tbody;
}
在上面的代码值=&#34;&#34;在表单的输入字段中。 添加工作正常,但添加数据后,我想编辑相同的公司和商店选择。
我在上面的代码中用于编辑数据,如下所示,但不适用于我。请帮帮我。
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="'if($config->metrcsettingconf_master_id == $store_products->master_id){ echo $config->metrcsettingconf_startdate} else{ echo ""}'">';