简体   繁体   中英

Php json_encode from mysql > output without column names

this is my code on a php page connected to mysql server.

$temp = array();
while($row = mysqli_fetch_assoc($result)) {
    $temp[] = $row;
}
echo json_encode($temp);

The output is:

[{"column1":"1448741941","column2":"951"},{"column1":"1448747281","column2":"862"}]

That's is including the column title + data, and i wanna know how can i get only datas, like

    [[1448741941,951],[1448747281,862]]

Thanks for the help!

Here is the quick answer, send in an array with the data only:

$temp = array();
while($row = mysqli_fetch_assoc($result)) {
    $temp[] = array( $row['column1'], $row['column2'] );
}
echo json_encode($temp);

Edit You might actually whant this too JSON_NUMERIC_CHECK :

$temp = array();
while($row = mysqli_fetch_assoc($result)) {
    $temp[] = array( $row['column1'], $row['column2'] );
}
echo json_encode($temp, JSON_NUMERIC_CHECK);

Another way is this:

    $temp[] = array( 
        intval( $row['column1'] ), 
        intval( $row['column2'] ) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM