[{
"SchoolId": "015-08-0034-009-37",
"SubjectId": "08-0034-00613",
"StudentId": "T-15981",
"StudentName": "John"
},{
"SchoolId": "015-08-0034-009-37",
"SubjectId": "08-0034-00613",
"StudentId": "T-15982",
"StudentName": "Paul"
}]
This is the json_encode response from my php page when i do echo if would look like this
Schoolid=015-08-0034-009-37
Subjectid=08-0034-00613
Studentid=T-15981
Studentname=John
Schoolid=015-08-0034-009-37
Subjectid=08-0034-00613
Studentid=T-15982
Studentname=Paul
I can get this result by doing like this
for (var i = 0; i < data.length; i++) {
console.log(data[i].schoolid);
console.log(data[i].subjectid);
console.log(data[i].studentid);
console.log(data[i].studentname);
}
How can i make it in a way that the value of same entry will be generated only once like the value of school id
and subject id
will be shown only once the unique value like student id
and student name
will be shown twice since there are two different values for it.
I am hoping to get the result as
Schoolid=015-08-0034-009-37
Subjectid=08-0034-00613
Studentid=T-15981
Studentname=John
Studentid=T-15982
Studentname=Paul
Where should i do the fixing for this one in php before passing the json_encode or in ajax after receiving the json_encode from php?
if ($stmt - > rowCount() > 0) {
while ($selected_row = $stmt - > fetch(PDO::FETCH_ASSOC)) {
$basicinfo[] = array('schoolid' => $selected_row['schoolid'], 'subjectid' => $selected_row['subjectid'], 'studentid' => $selected_row['studentid'], 'studentname' => $selected_row['studentname']);
//$basicinfo1[] = array('schoolid' => $selected_row['schoolid'], 'subjectid' => $selected_row['subjectid']);
//$basicinfo2[] = array('studentid' => $selected_row['studentid'], 'studentname' => $selected_row['studentname']);
}
//$merge = array_merge($basicinfo1 , $basicinfo2);
//$add = $basicinfo1 + $basicinfo2)
//$input = array_map("unserialize", array_unique(array_map("serialize", $merge)));
$input = array_map("unserialize", array_unique(array_map("serialize", $basicinfo)));
echo json_encode($input, JSON_UNESCAPED_UNICODE);
}