How to push values in array for JSON in php? -


in php, making array turned json string.

this works, if hardcode them:

                $data = array(                     'firstname' => mysql_result($recordset, 0, 'first name'),                     'lastname' => mysql_result($recordset, 0, 'last name'),                     'email' => mysql_result($recordset, 0, 'email address'),                     'password' => mysql_result($recordset, 0, 'password'),                     'phone' => mysql_result($recordset, 0, 'mobile number'),                     'website' => mysql_result($recordset, 0, 'website link'),                     'type' => mysql_result($recordset, 0, 'type_id'),                     'active' => mysql_result($recordset, 0, 'active'),                     'datejoined' => mysql_result($recordset, 0, 'date joined'),                     'dateleft' => mysql_result($recordset, 0, 'date left'),                     'datelastactive' => mysql_result($recordset, 0, 'date last active'),                     'status' => mysql_result($recordset, 0, 'status'),                     'biotext' => mysql_result($recordset, 0, 'bio text'),                     'picurl' => $picurl                 ); 

but if try loop

            $data = array();             ($i = 0; $i < $num_records; $i++) {                 array_push($data, "location{$i}" => mysql_result($recordset, $i, 'location'));             } 

i error

parse error: syntax error, unexpected t_double_arrow 

does know how fix this?

thanks

try

    $data = array();     ($i = 0; $i < $num_records; $i++) {        $data["location{$i}"] = mysql_result($recordset, $i, 'location');     } 

to make associative, , then

$myjson = json_encode($data); 

to json


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -