If loop to get data if present in table, if not then insert value into table and javascript to get profile id record data
I need an if loop in view file and javascript when entering a profile id, it should show all related elements in the form and I do this in codeignitor and this is part of the view file
<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>
here is my table: profile (Profile_id, profile_fname, profile_lname, PROFILE_EMAIL, profile_mobile, profile_type, profile_gender, profile_dob, profile_marital_status, profile_religion, profile_blood_group, profile_nationality, profile_iris, profile_biometric, profile_department, profile_project2 address) address
profile_id is a foreign key and its primary key is in another table as emp_acc_id
model for above:
public function reg_personal_details ()
{$ reg_personal_details = array (
// 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_designation'),);
$this->db->update('profile',$reg_personal_details);
source to share
You have to write a java Script that will check if a particular element exists or not. If its value is not zero, then dynamically generate new line tags and set its value, which we receive in response to the request. For dynamically creating a tag, you can link to the following page: -
http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/
source to share
we have a function to check if data is present or not, that is empty (), and we just need to use it in if, if so: if (! empty ($ var name)) "and can also use" if (empty ($ var name)) ", so if there is no data then it shows no error, and if data is present in db it shows that data
<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>
source to share