score:1
Accepted answer
this will return a json object with only one result.
if we use previous example, can be done like this:
$arr = $this->company->find('all'); // fetch the array
$arr1 = array();
foreach ($arr as $value) {
$tmp = array();
$tmp['name'] = $value['company']['nome'];
$tmp['data'] = count($value['branch']);
$arr1[] = $tmp;
}
return json_encode($arr1);
score:0
the whole idea is about like this
$arr=$this->company->find('all'); // fetch the array
$arr1=array();
foreach ($arr as $value) {
$arr1['name']=$value['company']['nome'];
//some more manual transform to desire format
}
return json_encode($arr1);
score:1
<?php
$sql=mysql_query("select * from posts limit 20");
$response = array();
$posts = array();
while($row=mysql_fetch_array($sql))
{
$title=$row['title'];
$url=$row['url'];
$posts[] = array('title'=> $title, 'url'=> $url);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?>
this will generate a file called results.json file where your php file is stored on your online server, taking url and title variables from your mysql db, you can change the variable names to what you want to fetch.
Source: stackoverflow.com
Related Query
- How would I convert this array to this json format
- How to transform this array in a json?
- How to insert json within an array into highcharts?
- how to sort and select top 5 elements in a json array using angular JS
- Python: How to transform DF into Json series?
- How would I convert this array to usable javascript array?
- How to make json object for this type in c#?
- How can I pass this array to a javascript function in an html.erb file, without erb evaluating the Date.UTC?
- Highcharts, how to get data from array on same js page instead of external JSON
- How to make this code more simple or shorten?
- how to map serial and data points using json Array
- How to make json array name series name, array data -series data in highcharts?
- how to load JSON for this highchart - django app
- how to display drilldown column highchart using json array objects - 3 level drilldown column highchart
- How to store highcharts compatible json array data in mongodb
- How to import JSON data to Chart Array in web2py (Python)
- How to fetch json array data into highcharts in angularjs
- How to build a JSON data array for Highcharts display - switching values for xAxis/columns
- How to pass multiple Highcharts parameters in JSON array
- How to pass json data to highcharts series?
- How do I set highcharts line graph point colors to an array of colors?
- Highcharts: How to load data from JSON to xAxis.categories and series.data?
- how to parse json into highcharts
- How to use this highchart map in reactJS
- How get data name in Highcharts pie chart legend instead of "Slice" using array of values?
- How to output JSON in python so it can be used for Geckoboard's Highcharts plugin
- How can I extend the lines of this Highchart series to the edges of my chart area?
- How to convert a JavaScript object to array
- How to populate a Highcharts axis with string formatted data from a PHP array
- Highcharts error #13: www.highcharts.com/errors/13 how to solve this error
More Query from same tag
- Highcharts 3D scatter points not showing names in tooltips
- highcharts get dashstyle from existing series
- How to disable color transition in highcharts gauge-solid
- Export Shiny page to PDF
- R - Highcharter, How to avoid increasing the indentation of the y axis label?
- React Highcharts include plugins
- How to display tooltip data below x-axis category labels using Highcharts
- adding extra series on highchart
- How to disable interaction animations on line chart but keep tooltips?
- Highcharts series.remove(false) doesn't update yAxis.datamax
- How to find series name in Highcharts for mouseOut-event?
- Always position Highcharts tooltip on top with respect to the marker point
- HighCharts - Make labels appear dynamically based on column size
- Can we have variable width of Bars in timeline chart in highchart?
- Validate in Shiny doesn't work as expected when making a highcharter treemap
- Highmaps shared tooltip for overlapping locations
- Gauge graph with gradient green-yellow-red
- Highcharts display scrollbar when zooming
- Highcharts: Getting x-axis to display legend
- Highchart - hide name in legend if no data
- Highcharts custom pattern fill shows different stroke width
- Highchart Line chart – data series with multiple axis - 2nd series placed in the middle of X axis
- How to access methods of wrapper Highcharts vue?
- renderHighcharts vs renderUI; Which one is faster when rendering several plots
- Create multiple Pie Highcharts for multiple series
- Trigger HighCharts Animation on View in Owl Carousel
- Map in Highcharts not display the India map?
- Highcharts / Highstock scroll bar and Zoom issue
- Highcharts Yaxis scale not showing
- Highcharts - update chart using ajax