How to show Row value of a database table into form?

How to show Row value of a database table into form?

hi friends,

i am getting a value form database and want to show only 2 columns value but i am unable to do this with this code..
This is PHP code to fetch data from database ;;
<?php
$stock=$_POST['stock'];
//echo $stock;
include("../dbconfig.php");


$result = mysql_query("SELECT * FROM stock where p_name='$stock'");            //query
//$array = mysql_fetch_row($result);                          //fetch result    
//$array = $array = mysql_fetch_array($result);                          //fetch result
$array = mysql_num_rows($result);                          //fetch result

  //--------------------------------------------------------------------------
  // 3) echo result as json 
  //--------------------------------------------------------------------------
//echo $id=$array['product_id'];
//echo $name=$array['p_name'];
//echo $total=$array['total'];
//echo $used=$array['used'];
//echo $balance=$array['balance'];

echo json_encode($array);
?> 

This is jquery code to retrive..

1st code--

$(document).ready(function(){
//alert("hello");
$("#stock").change( function(){
var stock=$("#stock").val();
//var rm_type = $('select[name="stock"]').val();
$.post('getstock.php',{stock: stock},
function(data){
var id = data[1];              
//var name = data[1];           
//var total = data[2];  
//var used = data[3]; 
//var balance = data[4];
//alert(balance);
//$("#total").val(total);         
//$("$used").val(used);       
//$("#balance").val(balance); 
$("#message").html(data);  
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file         
$("#msg").html("id:"+id);

// $('#message').html("id: "+id+" name:"+ name);
$("#msg").hide();
$("#msg").fadeIn(1500); //Fade in the data given by the insert.php file 


});
//alert(stock);
});


2nd code..

<script>
/////////////////////////
 $(function () 
  {

    //-------------------------------------------------------------------------------------------
    // 2) Send a http request with AJAX 
    //-------------------------------------------------------------------------------------------
    $.ajax({                                      
      url: 'getstock.php',                  //the script to call to get data          
      data: "",                        //you can insert url argumnets here to pass to api.php for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var id = data[0];              //get id
        var vname = data[1];           //get name
        //--------------------------------------------------------------------------------------
        // 3) Update html content
        //--------------------------------------------------------------------------------------
        $('#msg').html("<b>id: </b>"+id+"<b> name: </b>"+vname);     //Set output element html

      } 
    });
  
  }); 
</script>

i want to show these 3 value
var total = data[2];  
var used = data[3]; 
var balance = data[4];
 separately in 3 different div or textboxes etc

Thanks