in my script php i need to format an array end encode it an a json format starting from a select like this:
$result = mysql_query("SELECT datet,vototags,votodom FROM intro_s1 WHERE intro_s1.www = '".$url."' ORDER BY intro_s1.datet DESC");
$data = array(
array('Date', 'v1', 'v2'),
);
while ($row = mysql_fetch_array($result)) {
$data[] .= array($row['datet'], $row['vototags'], $row['votodom']);
}
echo json_encode($data);
I need that $ date is as follows:
[[Date,vi,v2],[11/02/2011,12,32],[12/06/2012,99,109][...]
instead my result is:
[["Date","v1","v2"],"Array","Array","Array","Array",[...]
ehat is wrong in my code?
Thanks in advance
You're using string concatenation with .=
on this line:
$data[] .= array($row['datet'], $row['vototags'], $row['votodom']);
Doing so converts the array into a string which gives you the Array
value.
If you remove the .
, it should give you the results you're aiming for:
$data[] = array($row['datet'], $row['vototags'], $row['votodom']);
Alternatively, if you really want to make sure you're adding a new element into the array, you can use array_push()
(if you don't care about the overhead of a function-call, that is):
array_push($data, array($row['datet'], $row['vototags'], $row['votodom']));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments