我想使用此學生ID號檢索學生參加的所有事件。所以這是我的PHP代碼,這個代碼正在工作,但它只能檢索1個事件,而這個學生已經參加了幾個事件。從JSON數組中檢索所有數據
<?php
$host='localhost';
$username='tan';
$password='1234567';
$db='feedback01';
$conn=mysqli_connect($host,$username,$password,$db);
if (!$conn)
{
die('Could not connect: ' . mysqli_connect_error());
}
$studentID=$_POST['StudentID'];
$studentID=mysqli_real_escape_string($conn,$studentID);
$query="SELECT * From PassportData WHERE StudentID='$studentID'";
$result=mysqli_query($conn,$query);
$response = array();
if(mysqli_num_rows($result)>0)
{
$row = mysqli_fetch_assoc($result);
$event = $row["Events"];
$date = $row["Date"];
$code = "login_success";
array_push($response, array("code"=>$code, "Events"=>$event, "Date"=>$date));
echo json_encode($response);
}
else{
$code = "login_failed";
$message = "not found!";
array_push($response, array("code"=>$code, "messsage"=>$message));
echo json_encode($response);
}
mysqli_close($conn);
?>
您應該循環$行= mysqli_fetch_assoc( $結果)該聲明。 –
*這是我的PHP代碼*那麼爲什麼將這個問題標記爲Java? –