我有這個我有這個非常簡單的表的噩夢。我正在嘗試創建一個草稿版。我有用戶和玩家。我希望用戶在每個玩家下面顯示爲<th>
,然後14個玩家<td>
。有點像這個..表格不輸出所有列
它只是創造的球員爲用戶提供了兩個列。而不是每個人。它也不會顯示它應該在的數據庫內容。顯示的玩家應該只在第一個位置(左邊的位置)。
這是它的代碼。
$draft_order_stmt = mysqli_query($con,"SELECT * FROM user_players ORDER BY `id`");
$draft_order_stmt2 = mysqli_query($con,"SELECT username FROM user_players ORDER BY `id`");
?>
<table class="draft_border_table">
<tr>
<th class="draft_table_number_th">RND</th>
<?php
while ($draft_user_row = mysqli_fetch_array($draft_order_stmt2)) {
$username = $draft_user_row['username'];
echo "<th class='draft_table_th'><div>" . $username . "</div></th>";
}
?>
</tr>
<?php
for ($count = 1; $count < 15; $count++) {
$col = "player" . $count;
$query = "SELECT $col FROM user_players ORDER BY id";
$draft_order_stmt2 = mysqli_query($con, $query);
$draft_order_row = mysqli_fetch_array($draft_order_stmt2);
echo "<tr><td>" . $count . "</td>";
foreach ($draft_order_row as $player) {
echo "<td><div class=\"draftBorder\">";
if (is_null($player)) {
$player = " ";
}
echo $player . "</div></td>";
}
echo "</tr>";
}
?>
</table>
我也試過這個,它顯示所有玩家的輸入,但玩家輸入都在一個塊中。像這樣...
user1的用戶2用戶3
所有14個玩家輸入
再次全部14個玩家輸入
再次全部14個玩家輸入
等。
這是我的代碼...
$draft_order_stmt = mysqli_query($con,"SELECT * FROM user_players ORDER BY `id`");
$draft_order_stmt2 = mysqli_query($con,"SELECT username FROM user_players ORDER BY `id`");
?>
<table class="draft_border_table">
<tr>
<th>Rnd</th>
<?php
while($draft_username_row = mysqli_fetch_array($draft_order_stmt2)) {
$username = $draft_username_row['username'];
?>
<th><?php echo "<div>" . $username . "</div>"; ?></th>
<?php
}
?>
</tr>
<?php
$count = 1;
while($draft_order_row = mysqli_fetch_array($draft_order_stmt)) {
$count + 1;
$player1 = $draft_order_row['player1'];
$player2 = $draft_order_row['player2'];
$player3 = $draft_order_row['player3'];
$player4 = $draft_order_row['player4'];
$player5 = $draft_order_row['player5'];
$player6 = $draft_order_row['player6'];
$player7 = $draft_order_row['player7'];
$player8 = $draft_order_row['player8'];
$player9 = $draft_order_row['player9'];
$player10 = $draft_order_row['player10'];
$player11 = $draft_order_row['player11'];
$player12 = $draft_order_row['player12'];
$player13 = $draft_order_row['player13'];
$player14 = $draft_order_row['player14'];
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player1 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player2 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player3 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player4 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player5 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player6 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player7 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player8 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player9 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player10 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player11 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player12 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player13 . "</div>"; ?></td>
<td><?php echo "<div class='draftBorder'>" . $player14 . "</div>"; ?></td>
</tr>
<?php
}
?>
</table>
有沒有人有任何想法我可以解決這個問題?
看起來你不小心覆蓋的'$ draft_order_stmt2'內容,讓你失去了你的第一個腳本的第二行中作出的第二個查詢的結果。 – arkascha
這條線? '1 $ draft_order_stmt2 = mysqli_query($ con,$ query);'我還能怎麼做呢? – Ralph
那麼,使用另一個第三個變量來保存第三個語句的結果。 – arkascha