1
function tableOne() {

        $query = mysql_query("SELECT valor FROM grafico") or die(mysql_error());
        $i = 0;
        while($row = mysql_fetch_assoc($query)) {
            $arr[] = array($row[valor]);
            ++$i;
        }
        echo json_encode($arr);
    }
}

the output will be

[["15573"],["31978"],["11227"],["5752"],["20817"],["32182"]]

i need something like:

["15573","31978","11227","5752","20817","32182","10935"]

i tried some changes in the code but the output is not what i want.

thanks

2 Answers 2

2

You are placing sub-arrays in each element of your array. You should replace

$arr[] = array($row[valor]);

with

$arr[] = $row[valor];

The [] in $arr[] already adds each entry as an element of the array.

Sign up to request clarification or add additional context in comments.

3 Comments

Also, please quote your array indices ('valor').
it is possible an output without quotes [15573,1978, 200]?
Try casting the values to an int: (int)$row[valor];
1
$query = mysql_query("SELECT valor FROM grafico") or die(mysql_error());

$arr = array();
while ($row = mysql_fetch_assoc($query)) {
    $arr[] = $row['valor'];  // get rid of the array() wrapper
}

echo json_encode($arr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.