Auto Complete Searching

Auto Complete

Php code for auto complete ————–


$product_name_string = array();

	$query_result 	= 	$db->query("SELECT * FROM products ORDER BY name");
	if($db->numRows($query_result)) {	
		while($row = $db->next_record($query_result)){
			//$product_name_string .='"'.trim($row['name']).'--'.$row['product_id'].'", ';
			array_push($product_name_string,array('label'=>$row['name'],'id'=>$row['product_id']));
		}
		$_SESSION['product_name_string'] = $product_name_string;
	}

Jquery code for auto complete ——————


$(document).ready(function(){
	////////////////// Searching Medicine ///////////////////////////////////////////
    var availableProducts = <? echo json_encode($_SESSION['product_name_string']);?>;	
    $(".search_text").live("focus", function() {
		$(".search_text").autocomplete({
			source: availableProducts,
			delay: 0,
			minLength:1,
			select: function (event, ui) { 
				productId = ui.item.id;				
				$("#product_id").val(productId);
			}			
		});	
	});

updating single field through ajax


javascript ------------->
$('.update_invoice_button').click(function(){
		var new_invoice_no = $(this).parent().find('.new_invoice_no').attr("value");		
		var fee_id = $(this).parent().find('.new_invoice_no').attr("width");		
		
		//return false;
		
			var form_data 	= {'table':'fee',
						   'where_column':'id',
						   'where_value':fee_id,
						   'update_column':'invoice_no',
						   'new_value':new_invoice_no
						   };		
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/reports/index.php?page=ajax_actions&action_page=update_field",
				data: form_data,
				success: function(result){
					var resultObj = jQuery.parseJSON(result);    		
					alert(resultObj.message)
				}
			});
		
	});

php on update_field -------------->
<?
$table 			= $_REQUEST['table'];
$where_column 	= $_REQUEST['where_column'];
$where_value 	= $_REQUEST['where_value'];
$update_column 	= $_REQUEST['update_column'];
$new_value 		= $_REQUEST['new_value'];

$sql = "UPDATE $table SET $update_column ='$new_value' WHERE $where_column=$where_value ";

$returnArray = array();
if(mysql_query($sql)){
	$returnArray['status'] = "success";	
	$returnArray['message'] = ucfirst($update_column)." updated successfully";
}else{
	$returnArray['status'] = "failure";
	$returnArray['message'] = "Error in updating, please contact admin";
}
echo json_encode($returnArray);
die;