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
- Size and offset for plotBackgroundImage in Highcharts
- Is Highmaps included in the .NET wrapper?
- Any chart library for funnel chart instead of highchart?
- Highcharts - Cross browser charts have different Y axis ranges, how can I ensure consistency?
- Highcharts: replace custom button image on hover
- Implement multiple AJAX-requested series via HighCharts
- Highcharts change serie type without change datalabels
- TypeError: p is not a function while calling map function in angular 4 for fetching series for bellcurve highchart
- How to link inside map to other map?, or how to change geojason dinaminacally?
- Highcharts Pie Graph
- Center of chart(pieChart)
- how can I use highcharts no-data-to-display module as es6-module?
- highchart stock : graph disappear when containing weekend data point
- Stacked column inside drilldown - HighCharts
- highcharter change highlight color on hover
- addpoint is not adding point in highcharts ,where data is updated dynamically with ajax
- How to display basic line graph in Highchart for multiple categories' data from csv?
- Is there a way to create Chord Diagram using Highcharts
- Change color of area chart programmatically in highcharts
- Highcharts Pie charts get the selected pie id
- Highcharts: Implement a second y-axis related to the first y-axis
- Changing unit on y-axis from million (M) to show multimillion (MM) in HighCharts
- Highchart legend symbol
- Highchart map does not support IRS country code
- Highcharts - Always keep hover state on single slice
- Highcharts - How to split up multiple charts in Rails 3
- Highcharts Orientation
- Chart Title overlapping on chart
- Formatting Negative Numbers with Dollar Sign in Highcharts
- Combining graphs in highcharts