Jquery json with Indice

Asked

Viewed 86 times

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:

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

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

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

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

1 answer

0


Try it like this

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.