Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用codeigniter中的循环更新多行时出错_Php_Codeigniter - Fatal编程技术网

Php 使用codeigniter中的循环更新多行时出错

Php 使用codeigniter中的循环更新多行时出错,php,codeigniter,Php,Codeigniter,当我尝试使用for循环更新详细信息时,它被更新为空(Null)以引用列 下面是我的代码,请帮助我我的逻辑有什么问题 查看代码 将生成的文本字段的数量取决于表中存在的值的数量。它在foreach循环中执行 <form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" <?php if ($advisor_emp->num_rows()>0 ) { $i=1; fo

当我尝试使用for循环更新详细信息时,它被更新为空(Null)以引用列

下面是我的代码,请帮助我我的逻辑有什么问题

查看代码
将生成的文本字段的数量取决于表中存在的值的数量。它在foreach循环中执行

<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" 
<?php
if ($advisor_emp->num_rows()>0 )
{
  $i=1;
  foreach($advisor_emp->result() as $data)
  {
    $eid = $data->id; 
    $cn = $data->company_name;
    $fd = $data->from_date;
    $td = $data->to_date;
    $tb = $data->type_of_buisness;
    $c1 = $data->company_addres_lane_1;
    $c2 = $data->company_addres_lane_2;
    $cc = $data->c_city;
    $cp = $data->c_pincode;
    $cs = $data->c_state;
    $cun = $data->c_country; ?>

    <div class="col-md-6">
         <div class="form-group">
             <input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
         </div>
         <div class="col-md-12">
              <div class="form-group">                  
                  <label>Previous Employer</label>
                  <input type="text" class="form-control" name="pcmp" value="<?php echo $cn; ?>">
               </div>
         </div>
         <div class="col-md-6">
             <div class="form-group">
                 <label>From</label>
                 <input type="text" name="pcmpfrom" class="form-control" value="<?php echo $fd ; ?>">
             </div>
         </div>
         <div class="col-md-6">
              <div class="form-group">
                   <label>To</label>
                   <input type="text" name="pcmpto" class="form-control" value="<?php echo $td ; ?>">
              </div>
         </div>
         <div class="col-md-12">
             <div class="form-group">
                <label>Designation</label>
                <input type="text" name="pcmpdesi" class="form-control" value="<?php echo  $tb;?>">
             </div>
         </div>
         <div class="col-md-6">
             <div class="form-group">
                 <label>Company Address Line 1</label>
                 <input type="text" name="pcmpadr1[]" class="form-control" value="<?php echo  $c1;?>">
             </div>
         </div>
         <div class="col-md-6">
             <div class="form-group">
                 <label>Company Address Line 2</label>
                 <input type="text" name="pcmpadr2" class="form-control" value="<?php echo  $c2;?>">
             </div>
         </div>
         <div class="col-md-6">
            <div class="form-group">
                <label>City</label>
                <input type="text" name="pcmpcit" class="form-control" value="<?php echo  $cc;?>">
            </div>
         </div>
         <div class="col-md-6">
             <div class="form-group">
                  <label>Pin Code</label>
                  <input type="text" name="pcmppin[]" class="form-control" value="<?php echo  $cp;?>">
              </div>
         </div>
         <div class="col-md-6">
             <div class="form-group">
                 <label>State</label>
                 <input type="text" name="pcmpstat[]" class="form-control" value="<?php echo $cs; ?>">
             </div>
          </div>
          <div class="col-md-6">
              <div class="form-group">
                  <label>Country</label>
                  <input type="text" name="pcmpcun[]" class="form-control" value="<?php echo $cun; ?>">
              </div>
          </div>
      </div>
      <?php 
        $i++;
      }  
  }
?>
<div class="col-md-12"
    <input type="submit" class="btn btn-primary" name="advisor_update" value="Update" >
</div>
</form>
视图代码 我已更改您的视图代码输入名称

<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" >
<?php
if ($advisor_emp->num_rows()>0 )
{
  foreach($advisor_emp->result() as $data)
  {
    $eid = $data->id; 
    $cn = $data->company_name;
    $fd = $data->from_date;
    $td = $data->to_date;
    $tb = $data->type_of_buisness;
    $c1 = $data->company_addres_lane_1;
    $c2 = $data->company_addres_lane_2;
    $cc = $data->c_city;
    $cp = $data->c_pincode;
    $cs = $data->c_state;
    $cun = $data->c_country; ?>

<div class="col-md-6">
     <div class="form-group">
         <input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
     </div>
     <div class="col-md-12">
          <div class="form-group">                  
              <label>Previous Employer</label>
              <input type="text" class="form-control" name="cn[]" value="<?php echo $cn; ?>">
           </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>From</label>
             <input type="text" name="fd[]" class="form-control" value="<?php echo $fd ; ?>">
         </div>
     </div>
     <div class="col-md-6">
          <div class="form-group">
               <label>To</label>
               <input type="text" name="td[]" class="form-control" value="<?php echo $td ; ?>">
          </div>
     </div>
     <div class="col-md-12">
         <div class="form-group">
            <label>Designation</label>
            <input type="text" name="tb[]" class="form-control" value="<?php echo  $tb;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 1</label>
             <input type="text" name="c1[]" class="form-control" value="<?php echo  $c1;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 2</label>
             <input type="text" name="c2[]" class="form-control" value="<?php echo  $c2;?>">
         </div>
     </div>
     <div class="col-md-6">
        <div class="form-group">
            <label>City</label>
            <input type="text" name="cc[]" class="form-control" value="<?php echo  $cc;?>">
        </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
              <label>Pin Code</label>
              <input type="text" name="cp[]" class="form-control" value="<?php echo  $cp;?>">
          </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>State</label>
             <input type="text" name="cs[]" class="form-control" value="<?php echo $cs; ?>">
         </div>
      </div>
      <div class="col-md-6">
          <div class="form-group">
              <label>Country</label>
              <input type="text" name="cun[]" class="form-control" value="<?php echo $cun; ?>">
          </div>
      </div>
  </div>
  <?php 
      }  
  }
?>
希望这对您有用

查看代码 我已更改您的视图代码输入名称

<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" >
<?php
if ($advisor_emp->num_rows()>0 )
{
  foreach($advisor_emp->result() as $data)
  {
    $eid = $data->id; 
    $cn = $data->company_name;
    $fd = $data->from_date;
    $td = $data->to_date;
    $tb = $data->type_of_buisness;
    $c1 = $data->company_addres_lane_1;
    $c2 = $data->company_addres_lane_2;
    $cc = $data->c_city;
    $cp = $data->c_pincode;
    $cs = $data->c_state;
    $cun = $data->c_country; ?>

<div class="col-md-6">
     <div class="form-group">
         <input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
     </div>
     <div class="col-md-12">
          <div class="form-group">                  
              <label>Previous Employer</label>
              <input type="text" class="form-control" name="cn[]" value="<?php echo $cn; ?>">
           </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>From</label>
             <input type="text" name="fd[]" class="form-control" value="<?php echo $fd ; ?>">
         </div>
     </div>
     <div class="col-md-6">
          <div class="form-group">
               <label>To</label>
               <input type="text" name="td[]" class="form-control" value="<?php echo $td ; ?>">
          </div>
     </div>
     <div class="col-md-12">
         <div class="form-group">
            <label>Designation</label>
            <input type="text" name="tb[]" class="form-control" value="<?php echo  $tb;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 1</label>
             <input type="text" name="c1[]" class="form-control" value="<?php echo  $c1;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 2</label>
             <input type="text" name="c2[]" class="form-control" value="<?php echo  $c2;?>">
         </div>
     </div>
     <div class="col-md-6">
        <div class="form-group">
            <label>City</label>
            <input type="text" name="cc[]" class="form-control" value="<?php echo  $cc;?>">
        </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
              <label>Pin Code</label>
              <input type="text" name="cp[]" class="form-control" value="<?php echo  $cp;?>">
          </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>State</label>
             <input type="text" name="cs[]" class="form-control" value="<?php echo $cs; ?>">
         </div>
      </div>
      <div class="col-md-6">
          <div class="form-group">
              <label>Country</label>
              <input type="text" name="cun[]" class="form-control" value="<?php echo $cun; ?>">
          </div>
      </div>
  </div>
  <?php 
      }  
  }
?>

希望这对您有用

您正在一次又一次地覆盖您的值,因此只会发布最后更新的值。将字段名更改为数组,或为其添加后缀“pcmpcit_u2;”。$i;这里$i可以是增量值,也可以正确地关闭标记。您中缺少的结束标记会一次又一次地覆盖您的值,所以只有最后更新的值才会被发布。将字段名更改为数组,或为其添加后缀“pcmpcit_u2;”。$i;这里$i可以是增量值,也可以正确关闭标记。缺少的结束标记不起作用。我遇到一个数据库错误@IvanIt不工作。我遇到了一个数据库错误@Ivan
<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" >
<?php
if ($advisor_emp->num_rows()>0 )
{
  foreach($advisor_emp->result() as $data)
  {
    $eid = $data->id; 
    $cn = $data->company_name;
    $fd = $data->from_date;
    $td = $data->to_date;
    $tb = $data->type_of_buisness;
    $c1 = $data->company_addres_lane_1;
    $c2 = $data->company_addres_lane_2;
    $cc = $data->c_city;
    $cp = $data->c_pincode;
    $cs = $data->c_state;
    $cun = $data->c_country; ?>

<div class="col-md-6">
     <div class="form-group">
         <input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
     </div>
     <div class="col-md-12">
          <div class="form-group">                  
              <label>Previous Employer</label>
              <input type="text" class="form-control" name="cn[]" value="<?php echo $cn; ?>">
           </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>From</label>
             <input type="text" name="fd[]" class="form-control" value="<?php echo $fd ; ?>">
         </div>
     </div>
     <div class="col-md-6">
          <div class="form-group">
               <label>To</label>
               <input type="text" name="td[]" class="form-control" value="<?php echo $td ; ?>">
          </div>
     </div>
     <div class="col-md-12">
         <div class="form-group">
            <label>Designation</label>
            <input type="text" name="tb[]" class="form-control" value="<?php echo  $tb;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 1</label>
             <input type="text" name="c1[]" class="form-control" value="<?php echo  $c1;?>">
         </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>Company Address Line 2</label>
             <input type="text" name="c2[]" class="form-control" value="<?php echo  $c2;?>">
         </div>
     </div>
     <div class="col-md-6">
        <div class="form-group">
            <label>City</label>
            <input type="text" name="cc[]" class="form-control" value="<?php echo  $cc;?>">
        </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
              <label>Pin Code</label>
              <input type="text" name="cp[]" class="form-control" value="<?php echo  $cp;?>">
          </div>
     </div>
     <div class="col-md-6">
         <div class="form-group">
             <label>State</label>
             <input type="text" name="cs[]" class="form-control" value="<?php echo $cs; ?>">
         </div>
      </div>
      <div class="col-md-6">
          <div class="form-group">
              <label>Country</label>
              <input type="text" name="cun[]" class="form-control" value="<?php echo $cun; ?>">
          </div>
      </div>
  </div>
  <?php 
      }  
  }
?>
if ($this->input->post('advisor_update'))
{
       $emp_his_id = $this->input->post('eid');    
       $cn = $this->input->post('cn');
       $fd = $this->input->post('fd');
       $td = $this->input->post('td');
       $td = $this->input->post('tb');
       $c1 = $this->input->post('c1');
       $c2 = $this->input->post('c2');
       $cc = $this->input->post('cc');
       $cp = $this->input->post('cp');
       foreach($emp_his_id as $key => $eid)
       {                        
            $emp_his_pk = $eid;
            $inserte = array();
            $inserte['company_name']= $cn[$key];
            $inserte['from_date']= $fd[$key];
            $inserte['to_date']= $td[$key];
            $inserte['type_of_buisness']= $tb[$key];
            $inserte['company_addres_lane_1']= $c1[$key];
            $inserte['company_addres_lane_2']= $c2[$key];
            $inserte['c_city']= $cc[$key];
            $inserte['c_pincode']= $cp[$key];
            $inserte['updated_on'] = date("Y-m-d");

            $up_emp_history=$this->Frontend_model->update_employe($inserte=array(),$emp_his_pk);
        }
   }