我得到了這個聲明(到目前爲止)的比賽腳本:MYSQL - 計數輪
SELECT COUNT(round) AS runden, COUNT(status) AS status FROM rounds AS r INNER JOIN player AS p ON r.playerID = p.id WHERE r.playerID = <ID>"
此表由特定用戶保存所有玩過回合。 如果用戶參與到一個圓,它會被寫入在該表中:
ID = ID
playerId =玩家
圓=所播放的圓(從1到4)
起到=如果Id的如果不是= 0,則用戶播放= 1
status =如果用戶贏得了本輪= 1,如果不是= 0
現在我需要的是所有播放的狀態= 1或狀態= 0的值所以我需要贏得總勝數和輸掉。
這顯示它:
function getRoundsByPlayer($playerId) {
$sql = "
SELECT COUNT(round) AS runden, COUNT(status) AS status FROM rounds AS r INNER JOIN player AS p ON r.playerID = p.id WHERE r.playerID = :playerId";
try {
$db = self::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("playerId", $playerId);
$stmt->execute();
$player = $stmt->fetch(PDO::FETCH_LAZY);
$db = null;
return $player;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
$runden = $helper->getRoundsByPlayer($row['id']);
和HTML:
...
<td><?php echo $runden->runden; ?></td>
...
如何通過不使用第二個或第三個SQL語句實現它?謝謝!
工程!謝謝! :) – Marek123 2013-04-07 22:44:14
你當然歡迎:D快樂編碼。 – peterm 2013-04-07 22:44:48