Json encode ,decode single row fetched from database


function abc(id)
{

	$("#id_of_registry").val(id);
	
	$.ajax({
         url:"get-ship-info.php",
	 type:"post",
	 dataType :"json",
	 data:{'id':id},
	 success:function(da){
	 
	 if(da == "1")
	 {
	 $("#addpro").show(0);
	 }
	 else{
	   $("#fname").val(da[0].fname);
           $("#lname").val(da[0].lname);
           $("#email").val(da[0].email);
           $("#phone1").val(da[0].phone1);
           $("#phone2").val(da[0].phone2);
           $("#phone3").val(da[0].phone3);
           $("#address").val(da[0].address);
           $("#city").val(da[0].city);
           $("#state").val(da[0].state);
           $("#zip").val(da[0].zip);
           $("#addpro").show(0);
  }
    }
});
}

in php file


$phone = $_POST['phone1']."-".$_POST['phone2']."-".$_POST['phone3'];
$out = mysql_query("select * from `bb_shipping_addresses` where `reg_id` = '".$_POST['id']."'");
$add = mysql_fetch_array($out);
$ph = explode('-',$add['phone']);
$num = mysql_num_rows($out);
$info = array();
if($num =="1"){
		$info[] = array( 'id' => $add['reg_id'],'fname'=>$add['fname'],'lname'=>$add['lname'],'email'=>$add['email'],'phone1'=>$ph[0],'phone2'=>$ph[1],'phone3'=>$ph[2],'address'=>$add['address'],'city'=>$add['city'],'state'=>$add['state'],'zip'=>$add['zip'] );
		echo json_encode($info);
}
else
{
		echo "1";
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s