Edit and Update multiple row

///////////////////////////// Edit and Update coding /////////////////////////////////////////////////////////////////
if(isset($_REQUEST['dependent_name'])){
	
		foreach($_REQUEST['dependent_name'] as $key=>$val){	
			if(is_array($_REQUEST['dependent_name'][$key])){
				foreach($_REQUEST['dependent_name'][$key] as $k=>$v){
					//echo $key."------->".$val."<br>";
					$dependenet_id = $k;
					$dependent_name = $_REQUEST['dependent_name'][$key][$k];
					$dependent_date_of_birth = ($_REQUEST['dependent_date_of_birth'][$key][$k] == '') ? '' : StringUtility::setFormatedDateBritish($_REQUEST['dependent_date_of_birth'][$key][$k]);
					 $query = "UPDATE student_brp_dependent SET 
							dependent_name = '".$dependent_name."',
							dependent_date_of_birth = '".$dependent_date_of_birth."' WHERE id = '".$dependenet_id."'";
					
					mysql_query($query);
				}
			}else{
				
				$dependent_name = $_REQUEST['dependent_name'][$key];
				$dependent_date_of_birth = ($_REQUEST['dependent_date_of_birth'][$key] == '') ? '' : StringUtility::setFormatedDateBritish($_REQUEST['dependent_date_of_birth'][$key]);
				$query = "INSERT INTO student_brp_dependent(brp_id,dependent_name,dependent_date_of_birth) VALUES('".$brp_id."','".$dependent_name."','".$dependent_date_of_birth."')";
				mysql_query($query);
			}
		  
		}
	}
//////////////////////////////////////// End edit and update coding /////////////////////////////////////////////
<!-------------------- HTML code for multiple row ----------------------------->
		<h2>Dependants</h2>
		<table id="dependants_table" border=1;>
		  <tr valign="top">
			<td style="font-weight:bold" width="10%">
					Dependant Name:
			</td>		
			<td style="font-weight:bold" width="10%">	
					Dependant Date of birth:
			</td>
		  </tr>
		  <?php
			if($brp_id >0){
			while($row_edit = mysql_fetch_array($result_edit)){
				$dependent_id = $row_edit['id'];
				$dependent_name = $row_edit['dependent_name'];
				$dependent_date_of_birth = $row_edit['dependent_date_of_birth'];
		  ?>
		  <tr>
				<td>
					<input type='text' style='width:80px;' class='dependent_name'  name='dependent_name[][<?=$dependent_id;?>]' value='<?php echo $dependent_name; ?>'/>
				</td>		
				<td>	
					<input type='text' style='width:80px;' class='dependent_date_of_birth'  name='dependent_date_of_birth[][<?=$dependent_id;?>]' value='<?php echo ($dependent_date_of_birth) ? StringUtility::getFormatedDateBritish($dependent_date_of_birth) : ""; ?>'/>
				</td>
		  </tr>
		  <?php } }?>
		</table>
		<div id="multi_row" style="float:left;margin-left:20px;cursor:pointer;border:0px solid red;">Add New Row (+)</div><br><br>
<!-------------------- End HTML code ------------------------->
//////////////////////////////// Java script code for multiple row ////////////////////////////////////////////
$('.dependent_date_of_birth').live('focus', function() {
		$(this).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-mm-yy',			
			yearRange: (new Date().getFullYear()-100)+ ':' + (new Date().getFullYear()+10),
			onSelect: function(){
			}
		}).datepicker('show');
		true;
	});
	$('#multi_row').click(function(){
		var dependent_name = "<input type='text' style='width:80px;' class='dependent_name'  name='dependent_name[]'/>";
		var dependent_date_of_birth = "<input type='text' style='width:80px;' class='dependent_date_of_birth'  name='dependent_date_of_birth[]'/>";
		var new_row_for_apply = "<tr><td>"+dependent_name+"</td><td>"+dependent_date_of_birth+"</td></tr>";
		$("#dependants_table").append(new_row_for_apply);
	});
////////////////////////////// end java script code //////////////////////////////////////////////////////////////

Leave a Reply

Your email address will not be published. Required fields are marked *