我需要此代码的帮助
$token = $_POST['token'];
$get_data = mysqli_query($db_con,"SELECT * FROM `app_login` WHERE `token`='$token'");
while ($d_token_data = mysqli_fetch_array($get_data)){
$code = $d_token_data['code'];
$get_acc_data = mysqli_query($db_con,"SELECT * FROM `students` WHERE `login_code`='$code'");
$d_get_data = mysqli_fetch_all($get_acc_data,MYSQLI_ASSOC);
echo json_encode(array('status' => '1' , 'data' => $d_get_data));
}
我得到了多行的信息
单排
我也尝试过 全部
$token = $_POST['token'];
$get_data = mysqli_query($db_con,"SELECT * FROM `app_login` WHERE `token`='$token'");
$d_token_data = mysqli_fetch_all($get_data,MYSQLI_ASSOC);
$code = $d_token_data['code'];
$get_acc_data = mysqli_query($db_con,"SELECT * FROM `students` WHERE `login_code`='$code'");
$d_get_data = mysqli_fetch_all($get_acc_data,MYSQLI_ASSOC);
echo json_encode(array('status' => '1' , 'data' => $d_get_data));
$token = $_POST['token'];
$get_data = mysqli_query($db_con,"SELECT * FROM `app_login` WHERE `token`='$token'");
$dataToReturn = [];
while ($d_token_data = mysqli_fetch_array($get_data)){
$code = $d_token_data['code'];
$get_acc_data = mysqli_query($db_con,"SELECT * FROM `students` WHERE `login_code`='$code'");
$d_get_data = mysqli_fetch_all($get_acc_data,MYSQLI_ASSOC);
$dataToReturn[] = $d_get_data;
}
echo json_encode(array('status' => '1' , 'data' => $dataToReturn));
您应该先准备数据,然后只返回一次数据。