Codeigniter:同一行的多列更新查询不起作用

时间:2016-08-01 03:40:38

标签: php mysql codeigniter codeigniter-2 globals

我无法使用与codeigniter中的userid匹配的行更新同一行的多个列。

我的控制器代码是:

exits.php



	function update_act_on_resignation(){
				global $SITE,$USER;
			$data = array();
			$data['row'] = new stdClass();
			$data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
			$data['offices']=$this->mod_common->get_all_offices();
			$clients = currentuserclients();
			$data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
			get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
			$data['error_message'] = '';
			$data['row']->id = $this->uri->segment(3);
			$data['id'] = $this->uri->segment(3);
			$data['action'] = 'add';
			$data['heading'] = 'Add';
			$data['msg_class'] = 'sukses';
			$data['path']=$path;
			$post_action = $this->input->post('action');
			if($post_action=='add' || $post_action =='update' ){
				$post_array = $this->input->post();
				$action = ($post_action == 'add')?'inserted':'updated';
				//echo '<pre>';print_r($SITE);die;
				echo $post_array['exit_type'] = 'Employee Initiated';
								echo $post_array[$id] = $USER->id; 
             echo $post_array['custom-105965']; 
             echo $post_array['manager_comments']; 
             echo $post_array['accept']; 
	         echo $post_array['agreed_last_date']; 
			

					$data['success_message'] = $this->exit_common->update_get_resignation_to_act($post_array,$action);


					if($data['success_message'] == 'Record '.$action.' successfully'){
						$data['row'] = new stdClass();
						$data['row']->id = $this->uri->segment(3);
						$data['row']->status = 1;

					}

			}
			
			$this->data['maincontent'] = $this->load->view('maincontents/view_resignation_action', $data,true);
			echo "Resignation withdrawn successfully!";
			
			$this->load->view('layout', $this->data);
		}
&#13;
&#13;
&#13;

我正在回应从表单中获得的结果,以检查我是否收到了已发送的表单元素,并且我已正确收到所有内容。即我收到$ $ post_array [$ id]是$ post_array [&#39; custom-105965&#39;] asd for $ post_array [&#39; manager_comments&#39;]接受$ post_array [&#39; ;在回声之后接受&#39;]和01-01-1970作为$ post_array [&#39; agree_last_date&#39;]。

我的模型代码是:

exit_common.php

&#13;
&#13;
	function update_get_resignation_to_act($post_array,$action){
			
	  $this->load->database(); 
   $this->db->where('userids', $post_array['id']); 
   $dbdata['discussion'] =  $post_array['custom-105965']; 
   $dbdata['manager_comments'] =  $post_array['manager_comments']; 
     $dbdata['last_status'] =  $post_array['accept']; 
	  $dbdata['agreed_date'] =  $post_array['agreed_last_date']; 
	
   $this->db->update('pr_resignation_requests', $dbdata);
				return;
						
			
			
		}
&#13;
&#13;
&#13;

我认为模型更新功能有问题。但是无法弄清楚什么是错误的,因为类似的函数正在用于更新db中的单个列。我错过了什么吗?它是一个mysql db。

我的观看代码是:

view_resignation_action.php

&#13;
&#13;
<style>
label{font-weight:bold;}

.hbox .col {
    display: table-cell;
    float: none;
    height: 100%;
    vertical-align: top;
	width:100%;
}
</style>
<div class="new">
   <section class="content-header">
          <h1>
			Resignation Action
          </h1>
          <ol class="breadcrumb" >
            <li><a href="<?php base_url(); ?>"><i class="fa fa-home"></i> Home</a></li>
            <li><a href="#">People Connect</a></li>
			<li><a href="<?php echo base_url(); ?>exits">Exit Tracker</a></li>
			<li class="active">Exit Details</li>
            
          </ol>
    </section>
	<input type="hidden" id="page_name" value="requests">	
	
 <div class="container-fluid">
                    <div class="row"> 
                        <!-- Thought Day-->
                        <div class="panel wrapper clearfix m-b-none">
              <!-- Horizontal Form -->
              
                <div class="box-header with-border">
                  
                </div><!-- /.box-header -->
                <!-- form start -->
					<?php if($error_message!=''){?>
								<div class="row-fluid return-message success-message <?php echo $msg_class; ?>"><?php echo $error_message;?></div>
							 <?php } else { ?>
                <?php echo form_open('exits/update_act_on_resignation/',array('name'=>'addostcstevent','id'=>'addostcstevent','method'=>'post','autocomplete'=>'on','class'=>'form-horizontal'))?>
					<?php echo form_hidden(array('id'=>$USER->id,'action'=>$action));?>
					
					<?php foreach($rows as $row){ ?>
                  <div class="panel-body">
					<div class="control-group form-group">
						<div class="col-md-6">
								
									   <div class="controls">  
									  <div class="col-md-5">
										
										<label class="control-label" style="text-align:left">Name of the employee </label>
										<div class="controls"><?php echo $row->firstname; ?>
										</div>
										
										</div>
										<div class="col-md-5">
										
										</div>
									  </div>
									</div>
						<div class="col-md-6 pull-right">
							<label class="control-label" style="text-align:left">Date of request </label><div class="controls">
										<?php echo $row->resignations_date; ?>
										</div>
						</div>
					</div>	
					<div class="clearfix"></div>					
					<div class="control-group form-group">
						<div class="col-md-6 ">
							<label class="control-label" style="text-align:left">Requested Last Working Date</label>
							<div class="controls">
							<div class="col-md-10">
									<?php echo $row->requested_date; ?>
									</div>
							</div>
						</div>
					
						<div class="col-md-6 pull-right">
							<label class="control-label">Reason</label>
						<div class="controls">
							<div class="col-md-9">
							<?php echo $row->exit_type; ?>  
							</div>
						</div>
					</div>
					
								<div class="col-md-6 pull-right">
							<label class="control-label">Comments from Employee</label>
						<div class="controls">
							<div class="col-md-9">
							<?php echo $row->comments; ?>  
							</div>
						</div>
					</div>
					
					
					
					<br><br><br><br><br><br><br>
					
					
					<fieldset id="f1" class="col-md-6 pull-left"> <!-- start fieldset -->
					

					<div class="label">
					


    </label>
</div>
<div class="input">

</div>
</div>
</td>
</table>
</td>
</tr>
<tr>
    <td>
        <table width="100%" style="text-align:left">
		
					<label class="control-label" style="text-align:left">Have you had a discussion with Employee?</label>
						<table>
							<td valign="top">
							<input id="custom-105965_0" class="custom-105965" name="custom-105965" value="Yes" type="radio">
							<label for="custom-105965_0">Yes
							<br>
							</label>
							</td>
							<td valign="top">
							<input id="custom-105965_1" class="custom-105965" name="custom-105965" value="No" type="radio">
							<label for="custom-105965_1">No
       
					</label>
				</td>
		</table>
            <td valign="top">
                <div class="fieldset" id="bsd-field-custom-105967-group">
						<div class="col-md-6 pull-left">
							<label class="control-label">Please enter your comments</label>
							<div class="controls">
							<div class="col-md-12">
							<textarea required class="form-control" name="manager_comments"></textarea>
								<!--<input placeholder="Please enter your comments" class="" id="dateofrequest" type="text" name="todays_date" value=""/>	<br><br>-->
							</div>
							</div>
							
							<label class="control-label">Action</label>
							<div class="controls">
							<div class="col-md-9">
							<?php $dd_list = array(
								'Accept'   => 'Accepted',
								'Reject'   => 'Rejected',
								);
							echo form_dropdown('accept', $dd_list, 'Accept');  
							?>	
							</div>
							</div>
							
							
							
							
						
							<label class="control-label">Agreed Last Working day</label>
							<div class="controls">
							<div class="col-md-9">
								<input placeholder="Agreed Last Working day" class=" m-wrap col-md-8 form-control " id="startdt" type="text" name="agreed_last_date" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
							</div>
							</div>
						
						<br><br>
						
							<div class="col-md-9">
							
							
				 			</div>
						
						
						
						
						</div>
				
		
					
                </div>
				<!-- If its a no -->
				           <div class="fieldset" id="bsd-field-custom-105867-group">
						<div class="col-md-6 pull-left">
				
						
							<div class="alert alert-success alert-dismissable">
            <label type="button"></label>
            Please have a discussion with the employee.
        </div>
						
						
						
						</div>
				
		
					
                </div>
            </td>
        </table>
    </td>
</tr>

					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
						
					</fieldset><!-- End Fiedset -->
					
				</div>
				</div>
					<?php }?>
				 <div class="clearfix"></div>
				<div class=" box-footer">
					<button type="submit" class="btn btn-info pull-right" style="margin:0px 10px">submit</button>
					
				</div>
				</form>
							 <?php } ?>
				<div class="clearfix"></div>
			</div>
		</div>
		</div>
	</section>
	</div>
	<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-fileupload/bootstrap-fileupload.js"></script>
	<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/select2/select2.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.js"></script>

<script>
$(".fieldset").hide();
		$(document).ready(function () {
    $("[id^=bsd-field-custom-1059]").hide();
    $(".custom-105965").change(function () {
        $("[id^=bsd-field-custom-1059]").toggle(this.value == 'Yes');
    });
	
});
$(document).ready(function () {
    $("[id^=bsd-field-custom-1059]").hide();
    $(".custom-105965").change(function () {
        $("[id^=bsd-field-custom-1058]").toggle(this.value == 'No');
		      $('.alert').show()
    });
	
});
$(document).ready(function(){
		$("#startdt").datepicker({
			dateFormat: 'dd-mm-yy',
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true,
			yearRange: "-90:+0",
			endDate: new Date(),
			autoclose: true
		}).on('changeDate', function (selected) {
			var minDate = new Date(selected.date.valueOf());
			$('#enddt').datepicker('setStartDate', minDate);
		});
		$("#enddt").datepicker({ 
			dateFormat: 'dd-mm-yy',
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true,
			yearRange: "-90:+0",
			endDate: new Date()
		});
		$(".date-picker").datepicker();
		 $('.timepicker-default').timepicker();
		 $('#report_date').datepicker( {
			format: "mm-yyyy",
			 viewMode: "months", 
			 minViewMode: "months"
		});
		
			$(".select2").select2({
				placeholder: "Select an option",
				allowClear: true
			});
				$("#asset_type").change(function(){
					if($(this).val() == '-1') {
						$("#new_type").show();
					}
					else
					{
						$("#new_type").hide();
					}
				});

				$("#manufacturer").change(function(){
					if($(this).val() == '-1') {
						$("#new_manufacturer").show();
					}
					else
					{
						$("#new_manufacturer").hide();
					}
				});

				$("#supplier").change(function(){
					if($(this).val() == '-1') {
						$("#new_supplier").show();
					}
					else
					{
						$("#new_supplier").hide();
					}
				});
		});
		

		
</script>
&#13;
&#13;
&#13;

Mysql表是:enter image description here

1 个答案:

答案 0 :(得分:3)

尝试以下代码段

function update_get_resignation_to_act($post_array,$action)
{       
     $this->load->database(); 
     $this->db->where('userids', $post_array['id']); 
     $dbdata = array(
          "discussion" => $post_array['custom-105965'],
          "manager_comments" => $post_array['manager_comments'],
          "last_status" => $post_array['accept'],
          "agreed_date" => $post_array['agreed_last_date']
     ); 
     $this->db->update('pr_resignation_requests', $dbdata);
     /**
     * if required add this code here to check
     *
     * echo $this->db->last_query();
     */
     return;    
}
相关问题