我需要视图文件中的if循环和一个javascript,当输入概要文件id时,它应该显示表单中的所有相关元素,我在codeignator中这样做,这是视图文件的一部分
<tr>
<td width='50%'>
<table width="50%"><tr>
<td width="50%"><strong>Profile ID </strong></td>
<td width="50%"><input type="text" id="profile_id" name="profile_id" value="<?php echo $reg_personal_details->profile_id;?>"placeholder="Employee ID "/><?php echo form_error('profile_id');?><br></td>
</tr>
<tr>
<td><strong>Employee Name </strong></td>
<td><input type="text" id="profile_fname" name="profile_fname" value="<?php echo $reg_personal_details->profile_fname;?>"placeholder="Employee Name"/><?php echo form_error('profile_fname'); ?><br></td>
</tr>
<tr>
<td><strong>Employee Type </strong></td>
<td>
<input type="text" id="profile_type" name="profile_type" value="<?php echo $reg_personal_details->profile_type;?>"placeholder="Employee Type"/><?php echo form_error('profile_type');?><br>
</td>
</tr>
<tr>
这是我的桌子:轮廓(profile_id,profile_fname,profile_lname,profile_email,profile_ mobile,profile_ type,profile_ gender,profile_dob,profile_ marital_,profile_宗教,profile_ blood_group,profile_ nationality,profile_ iris,profile_ biometric,profile_ department,profile_ designation,profile_ project_,profile_ image,地址_ 1,address_2(
profile_id是一个外键,它的主键在另一个表中作为emp_acc_id
上面的模型是:
公共函数reg_personal_details((
{$reg_personal_details=阵列(
// i also need a condition here to read the entered profile_id all that below data must be store in that id only//
'profile_type' => $this->input->post('profile_type'),
'profile_gender' => $this->input->post('profile_gender'),
'profile_dob' => $this->input->post('profile_dob'),
'profile_marital_status' => $this->input->post('profile_marital_status'),
'profile_religion' => $this->input->post('profile_religion'),
'profile_blood_group' => $this->input->post('profile_blood_group'),
'profile_nationality' => $this->input->post('profile_nationality'),
'profile_iris' => $this->input->post('profile_iris'),
'profile_biometric' => $this->input->post('profile_biometric'),
'profile_department' => $this->input->post('profile_department'),
'profile_designation' => $this->input->post('profile_designation'),
'profile_project_designation'=>$this->input->post('profile.project_deignation'(,);
$this->db->update('profile',$reg_personal_details);
您应该编写一个java脚本,检查特定元素是否存在,即其值是否为null,然后动态生成一个新行标记,并将其值设置为我们在响应查询时获得的值。要动态生成标签,您可以参考以下页面:-
http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/
我们有一个函数来检查数据是否存在,即empty((,我们只需要在if循环中使用它,如"if(!empty($var name((",也可以使用"if(empty($var name(
<tr>
<td width='50%'>
<table width="50%"><tr>
<td width="50%"><strong>Profile ID </strong></td>
<td width="50%"><input type="text" id="profile_id" name="profile_id" value="<?php
if (!empty($reg_personal_details)) {
echo $reg_personal_details->profile_id;
} else
echo $profile_id;
?>"placeholder="Employee ID "/><?php echo form_error('profile_id'); ?><br></td>
</tr>
<?php //if($reg_personal_details!=array()){ ?>
<td><strong>Employee Name </strong></td>
<td>
<input type="text" id="profile_fname" name="profile_fname" value="<?php
if (!empty($reg_personal_details)) {
echo $reg_personal_details->profile_fname;
}
?>" placeholder="Employee Name"/><?php echo form_error('profile_fname'); ?><br>
</td>
</tr>
<tr>
<td><strong>Employee Type </strong></td>
<td>
<input type="text" id="profile_type" name="profile_type" value="<?php
if (!empty($reg_personal_details)) {
echo $reg_personal_details->profile_type;
}
?>"placeholder="Employee Type 0/1"/><?php echo form_error('profile_type'); ?><br>
</td>
</tr>
<tr>