I'm pulling data from a database table using php. I'm creating a simple string that provides information to a chart.
Here is the current code and out put:
$tsq7a = "SELECT * FROM FactDayUtilv1"; $stmt7a = sqlsrv_query( $conn, $tsq7a); $data7a = ""; while( $row = sqlsrv_fetch_array( $stmt7a, SQLSRV_FETCH_NUMERIC)){ $data7a .= "{name: '"; $data7a .= "$row[2]"; $data7a .= "', y: "; $data7a .= "$row[3]"; $data7a .= ", drilldown: 'D"; $data7a .= "$row[2]"; $data7a .= "'},"; } $data7a = substr($data7a,0,strlen($data7a)-1); Creates the following output.
{name: '1', y: 65, drilldown: 'D1'},{name: '2', y: 66, drilldown: 'D2'},{name: '3', y: 54, drilldown: 'D3'},{name: '4', y: 71, drilldown: 'D4'},{name: '5', y: 43, drilldown: 'D5'},{name: '6', y: 12, drilldown: 'D6'},{name: '7', y: 8, drilldown: 'D7'}
I'm trying to replace the '1' '2' '3' '4' '5' '6' '7' in the output to the days of the week as below:
{name: 'Mon', y: 65, drilldown: 'D1'},{name: 'Tue', y: 66, drilldown: 'D2'},{name: 'Wed', y: 54, drilldown: 'D3'},{name: 'Thu', y: 71, drilldown: 'D4'},{name: 'Fri', y: 43, drilldown: 'D5'},{name: 'Sat', y: 12, drilldown: 'D6'},{name: 'Sun', y: 8, drilldown: 'D7'}
I've been trying str_replace or str_ireplace with no luck.
Any help appreciated.
Thanks Rob
json_encodethat will encode you data properly.