简体   繁体   English

如果不存在,如果循环获取数据(如果不存在则在表中),则在表和javascript中插入值以获取写入配置文件ID的数据

[英]if loop to get data if present in table if not present then insert value in table and javascript to get the data on writing profile id

I need a if loop in view file and a javascript when profile id is entered it should show all the related elements in the form and i'm doing this in codeignitor and this is the part of view file 我需要一个if循环视图文件和一个javascript,当输入配置文件ID时,它应该显示表单中的所有相关元素,我在codeignitor中这样做,这是视图文件的一部分

                        <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_designation, profile_project_designation, profile_image, address_1, address_2) 这是我的表: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_designation,profile_project_designation,profile_image,address_1,address_2)

profile_id is a foreign key and its primary key is in other table as emp_acc_id profile_id是外键,其主键在emp_acc_id的其他表中

model for the above is : 以上模型是:

public function reg_personal_details() 公共函数reg_personal_details()

{ $reg_personal_details = array( {$ 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'), ); 'profile_project_designation'=> $ this-> input-> post('profile_project_designation'),);

    $this->db->update('profile',$reg_personal_details);

You Should write a java Script which would check if a particular element exists or not ie if its value is not null then generate a new row tags dynamically and set its value what we get in response of the query. 您应该编写一个java脚本来检查特定元素是否存在,即如果其值不为null,则动态生成新的行标记,并将其值设置为我们获得的响应查询的值。 For generating a tag dynamically you can refer the following page:- 要动态生成标记,可以参考以下页面: -

http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/ http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/

we have a function to check whether data is present or not ie, empty()and we just need to use it in if loop like this "if (!empty($var name))" and can also use "if(empty($var name)) " so if there is no data then it doesn't show any error and if data is present in db it shows that data 我们有一个函数来检查数据是否存在,即empty(),我们只需要在if循环中使用它“if(!empty($ var name))”并且也可以使用“if(empty(empty) $ var name))“所以如果没有数据那么它就不会显示任何错误,如果数据存在于db中它会显示数据

<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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM