Posted in Javascript, JSON, PHP, SQL

Javascript – Building arrays from JSON response data

function getPerformanceinfo (){

var myLabelarray = [];
var myActualarray = [];

$.post(‘inl_sev_078_J_vrs.php’, {“UNIQUENO” : myReportref }, function(response) {

for(var i=0; i<response.length; i++) {

myLabelarray[i] = response[i]._TAK;

myActualarray[i] = response[i]._PERCENTAGE;

}

myChartjs (myLabelarray, myActualarray);

}, ‘json’)

}


 

// — Parameters input ——————————————————–

$uniqueno = (isset($_REQUEST[‘UNIQUENO’])) ? $_REQUEST[‘UNIQUENO’] : ”;

// — Define containers ——————————————————-

$terugvoer = array();
$tmp = array();

// — Extract the category names and weights ——————————

$sql = “SELECT _QUESTIONNAIRE, _VERSION, _TAK, _PERCENTAGE FROM performance WHERE _UNIQUENO = ‘$uniqueno’ “;

$db = new MysqliDb(‘CES’);

$selectStatus = $db->rawQuery($sql);

foreach ($selectStatus as $row) {

$tmp[‘_QUESTIONNAIRE’] = $row[‘_QUESTIONNAIRE’];
$tmp[‘_VERSION’] = $row[‘_VERSION’];
$tmp[‘_TAK’] = $row[‘_TAK’];
$tmp[‘_PERCENTAGE’] = $row[‘_PERCENTAGE’];

$terugvoer[] = $tmp;

}

// echo ‘<pre>’;
// print_r($terugvoer);
// echo ‘</pre>’;

echo json_encode($terugvoer);

Advertisements