Jquery json with index

0

I need to create a Json result, where the state is the index.

<?php 
//header('Content-Type: application/json; charset=utf-8'); 

require_once('Connections/conexao.php');

$selec = "SELECT estado, kg, valorCap, valorExcedCap, valorAloremCap, prazoCap FROM transportadoras_valores WHERE id_transportadora = '".$_GET["id_transportadora"]."' "; 
$exec = mysql_query($selec, $conexao) or die(mysql_error()); 

while($campos=mysql_fetch_array($exec)) { 
    extract($campos); 
    $Array = Array(); 

    $Array[] = Array(
                        "estadoT"           => "$estado",
                        "valorCap"          => "$valorCap",
                        "valorExcedCap"     => "$valorExcedCap",
                        "valorAloremCap"    => "$valorAloremCap",
                        "prazoCap"          => "$prazoCap",
                    ); 

    $json_encode = json_encode($Array); 
    echo "<pre>";
    print_r($json_encode); 
    echo "</pre>";
} 
?>

RESULT OF THE ABOVE CODE:

  

[{"stateT": "AL", "kg": "3"}]

     

[{"stateT": "AL", "kg": "5"}]

     

[{"stateT": "AL", "kg": "10"}]

     

[{"stateT": "AM", "kg": "3"}]

    
asked by anonymous 13.05.2015 / 02:00

1 answer

0

Try this way

$Array[$estado] = array(
                        "estadoT"           => "$estado",
                        "valorCap"          => "$valorCap",
                        "valorExcedCap"     => "$valorExcedCap",
                        "valorAloremCap"    => "$valorAloremCap",
                        "prazoCap"          => "$prazoCap",
                    );
    
13.05.2015 / 02:05