我正在尝试遍历来自 MySQL 的结果列表,并以 HTML 表格格式显示所有唯一的游戏名称和每个游戏名称的计数。它可以正常工作,直到最后一行不显示名称或计数。如果姓氏有多行,则显示名称但不显示计数。
我的代码:
$propertyGameQuery = "SELECT G.GAME_NAME FROM GAMES AS G, PROPERTY_GAMES AS PG WHERE PG.PROPERTY_ID=$cid AND G.ID=PG.GAME_ID ORDER BY G.GAME_NAME";
$propertyGameResult = mysql_query($propertyGameQuery);
$gameCount = 0;
$rowCounter = 0;
$number = mysql_num_rows($propertyGameResult);
$rws = mysql_fetch_assoc($propertyGameResult);
$starterName = $rws['GAME_NAME'];
while($propertyGames = mysql_fetch_assoc($propertyGameResult)) {
$currentGameName = $propertyGames['GAME_NAME'];
if(($gameCount == 0) or ($rowCounter == $number)){
?>
<tr class="game-table"><td width="80%" title="<? echo $currentGameName; ?>" align="left" style="padding-left:5px;"><? echo $rowCounter ?> <? echo $currentGameName; ?></td>
<?
}
if(($currentGameName == $starterName) or ($lastGameName == $currentGameName)){
$gameCount = $gameCount + 1;
}else{
?>
<td width="20%" align="center"><? echo $gameCount + 1; ?></td></tr>
<?
$gameCount = 0;
} ?>
<?
$lastGameName = $currentGameName;
$rowCounter++;
}