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

时间:2015-12-05 03:39:07

标签: php android sql

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

<?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);

&GT;

0 个答案:

没有答案