I have written a script to query a mysql database and encode the data in json format.
I have added $encoded = json_encode($encodable[0]); which removes the other [ ] brackets but then only displays 1 record. Is there a way to still remove those brackets but display for example every record that I am querying?
Sorry not sure how to describe the problem in a better way!
Encode the result set of the query as JSON? Or encode data that is being sent to the database??
$encodeable[0] is the first element of the array, so its clear that that is what will be encoded. Depending on the format of your data,
encodeable[0]would be[{"key":"value"},{"key":"value"},{"key":"value"}]by default as thats an indexed array with keys of 0,1,2…If your goal is to just output the json as a JS object
{}, instead of an array[]you can usejson_encode($array, JSON_FORCE_OBJECT);which will encode indexed arrays as{"0":"value"}or{"0":{"0":"value"}}instead of just["value"]or[["value"]]. If that’s not what you’re after, you may just need to loop through each encodeable element of your array and encode that way (use a for loop)http://php.net/manual/en/function.json-encode.php