This question is not an programming question exactly. I have a requirement of making a JSON output of the picture shown. I know the usage of json_encode() but the problem is I am not getting how logically I will show these details.
The output I got is:
{"name":"ZXY","success":1,"subjects":["DIGITAL COMMUNICATION TECHNIQUE(2012-13)","DIGITAL SIGNAL PROCESSING(2012-13)","ANTENNAS AND WAVE PROPAGATION(2012-13)","DIGITAL SWITCHING THEORY AND NETWORKS(2012-13)","ACCOUNTING FOR MANAGERS(2012-13)","DIGITAL COMMUNICATION TECHNIQUE LAB(2012-13)","DIGITAL SIGNAL PROCESSING LAB(2012-13)"]}
.
Please tell me what can be a valid JSON output of the details I have,
Edit: I have to get a JSON output from the MySQL data. A sample data of a student I have provided in the image. The JSON Which I have shown is the result of a PHP page, I am not satisfied with the JSON output I am getting. I am asking for a better way to represent the data in effective manner in JSON format.
This is the PHP code which I have written for getting JSON output.
<?php
$regno = $_GET['regno'];
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'android_app_details';
$dbc = mysqli_connect($host,$user,$password,$database)
or die('Error in connecting the database');
$query =
"SELECT SD.REGNO, STD.FNAME, STD.MNAME, STD.LNAME, SD.SUBJECT_NAME, AD.PRESENT_COUNT, AD.TOTAL_COUNT ".
"FROM ATTENDANCE_DETAILS AS AD, SUBJECT_DETAILS AS SD, STUDENT_DETAILS STD ".
"WHERE AD.ENROLLMENT_ID = SD.ENROLLMENT_ID ".
"AND SD.REGNO = '".$regno."' ".
"AND AD.BATCH_SUBJECT_ID = SD.BATCH_SUBJECT_ID ".
"AND SD.STUDENT_ID = STD.STUDENT_ID ";
$result = mysqli_query($dbc, $query)
or die('Error in query');
$subject = Array();
$att = Array();
$total = Array();
$i = 0;
$success = 0;
while($row = mysqli_fetch_array($result)){
if($row['MNAME'])
$name = $row['FNAME'].' '.$row['MNAME'].' '.$row['LNAME'];
else
$name = $row['FNAME'].' '.$row['LNAME'];
$subject[$i] = $row['SUBJECT_NAME'];
$i++;
$success = 1;
}
if($success)
$response = array(
"name" => $name,
"success" => $success,
"subjects" => $subject
);
else
$response = array(
"success" => $success
);
echo json_encode($response);
?>
tagnameshence accessing them would be difficult..subjects. They're simply in an array and you can access each of them iterating the array usingsubjects[i]. What different tagname would you want for them?{}right? As per this definition the array is not valid.