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

}

エリアで// HERE I WANT TO MAKE A NEW CALL //これを実行したい:

$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'];

= と != を除いて、2 つの呼び出しは同じです。これは同じステートメントで実行できますか?

前もって感謝します :-)

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 に答える