我正在运行一个使用 PHP 从 Web 服务器检索数据的移动应用程序。
当我在 sql 查询中运行 SQL 语句时,它会返回正确的数据。
当我运行 PHP 时,它为 gameArray 中位置 0 的项目返回空值,数组中的所有其他项目都显示正确的值
代码如下
$userResponse = array(
'login' => $userName,
'nickname' => $userNickName);
$stmt = $conn->gamedb->prepare("SELECT player1, player2, currentturn, question1, question2, question3, question4, question5, question6, question7, question8, question9 FROM Game WHERE Player1 = ? OR Player2 = ?");
$stmt->bind_param('ss', $userName, $userName);
$stmt->execute();
$result = $stmt->store_result();
//create games array to be filled when stepping through the games
$gameResponse = array();
if($conn->gamedb->affected_rows > 0)
{
while ($stmt->fetch())
{
$stmt->bind_result($player1, $player2, $currentTurn,
$question1, $question2, $question3,
$question4, $question5, $question6,
$question7, $question8, $question9);
$gameArray = array($player1, $player2, $currentTurn,
$question1, $question2, $question3,
$question4, $question5, $question6,
$question7, $question8, $question9);
//stores the game data into an array
$gameResponse[] = $gameArray;
}
//close stmt
$stmt->close();
}
$response = array(
$userResponse,
$gameResponse
);
echo json_encode($response);
任何帮助都是极好的!