這個問題不完全是一個編程問題。我有要求顯示圖片的JSON輸出。我知道json_encode()
的用法,但問題是我沒有得到如何邏輯我會顯示這些細節。PHP中表格的JSON輸出
我得到的輸出是:
{"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)"]}
。
請告訴我什麼都可以的我有細節的有效JSON輸出,
編輯:我得從MySQL數據輸出JSON。我在圖片中提供的學生的示例數據。我已經顯示的JSON是PHP頁面的結果,我不滿意我得到的JSON輸出。我正在尋求一種更好的方式來以JSON格式有效地表示數據。
這是我爲獲取JSON輸出而編寫的PHP代碼。
<?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);
?>
發表一些代碼。 – Yogus
您當前的JSON輸出究竟有什麼問題? – Onheiron
那麼,首先,主體沒有任何'標記名',因此訪問它們將會很困難.. – NewUser