SQL-如何在php中返回具有相同字段的多行

SQL-如何在php中返回具有相同字段的多行,php,android,sql,Php,Android,Sql,我使用这个php脚本从android应用程序访问远程数据库。我正在尝试搜索具有特定位置的游戏,以查找该位置正在进行的所有游戏。问题是我的php文件只返回我最近创建的游戏,如果有两个游戏的“位置”值相同,有没有一种方法可以让我逐个返回所有游戏 <?php /*server, user, password, databse */ $conn=mysqli_connect("x", "x", "x","x"); if (mysqli_connect_errno()) { printf("Conn

我使用这个php脚本从android应用程序访问远程数据库。我正在尝试搜索具有特定位置的游戏,以查找该位置正在进行的所有游戏。问题是我的php文件只返回我最近创建的游戏,如果有两个游戏的“位置”值相同,有没有一种方法可以让我逐个返回所有游戏

<?php
/*server, user, password, databse */
$conn=mysqli_connect("x", "x", "x","x");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$location = $_POST["location"];

$statement = mysqli_prepare($conn, "SELECT * FROM Games WHERE location = ?");
if($statement === FALSE){ die(mysqli_error($conn)); }

mysqli_stmt_bind_param($statement, "s", $location);
mysqli_stmt_execute($statement);
//printf("Error: %s.\n", mysqli_stmt_error($statement));

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $user, $time, $date, $num_players, $location);

    $game = array ();

    while(mysqli_stmt_fetch($statement)){
        $game[user] = $user;
        $game[time] = $time;
        $game[date] = $date;
        $game[num_players] = $num_players;
        $game[location] = $location;
    }

    echo json_encode($game);


mysqli_stmt_close($statement);

mysqli_close($conn);

您的数据结构是什么?我有一个名为Games的表,该表存储了通过应用程序创建的所有游戏。在同一个位置可以有多个游戏,当我使用这个php代码时,它只会返回我最近创建的带有指定位置的游戏。您可以在mysql控制台中运行该查询(“SELECT*FROM games WHERE location=?”)。结果是什么?我基本上运行的select语句是select*FROM Games WHERE location=“Lady Bug Park”;当我在控制台中运行它时,它返回所有4个位置为ladybug的游戏park@BryanPenaloza,查看“mysqli_stmt_fetch”的文档:;它表示此函数将在出错时返回false,并在结束时返回null。检查“mysqli_stmt_fetch”的返回值。