1

我试图弄清楚如何创建准备好的语句。我现在有这个:

$stmt = $mysqli->stmt_init();

if($stmt->prepare("SELECT fk_player_id, player_draws, player_turn, player_passes, swapped FROM ".$prefix."_gameplayer WHERE fk_game_id = ? AND fk_player_id = ?")){

    $stmt->bind_param('ii', $currgame, $playerid);
    $stmt->execute();
    $stmt->bind_result($playerid, $udraws, $uturn, $upass, $uswaps);
    $stmt->fetch();

    // HERE I WANT TO MAKE A NEW CALL //

    $stmt->close(); 

}

在该区域// 这里我想打一个新电话 //我想运行这个:

$sql = mysql_query("SELECT fk_player_id, player_tiles, player_draws, player_turn, player_passes, swapped FROM ".$prefix."_gameplayer WHERE fk_game_id = $currgame AND fk_player_id != $playerid");
$row = mysql_fetch_assoc($sql);

$opponent = $row['fk_player_id'];
$oppTiles = $row['player_tiles'];

$odraws = $row['player_draws']+1;
$oturn = $row['player_turn'];
$opass = $row['player_passes'];
$oswaps = $row['swapped'];

除了 = 和 != 之外,这两个调用是相同的。这可以在同一个语句中完成吗?

提前致谢 :-)

4

1 回答 1

1

据我了解您的问题,您需要所有玩家。
好吧,全选。您可以在显示时分开

$sql = "SELECT * FROM {$prefix}_gameplayer WHERE fk_game_id = ?";
$stmt = $mysqli->stmt_init();

$data = array();
if($stmt->prepare($sql)){
    $stmt->bind_param('i', $currgame);
    $stmt->execute();
    $res = $stmt->get_result();
    while ($ow = $res->fetch_assoc()) {
        $data[] = $row;
    }
    $stmt->close(); 
}
// to display own games
foreach ($data as $row) {
    if ($row['fk_player_id'] == $playerid) {
        // do something
    }
}
// to display other games
foreach ($data as $row) {
    if ($row['fk_player_id'] != $playerid) {
        // do something
    }
}
于 2013-02-02T14:37:51.747 回答