是否可以使用一个数组来保存mysql查询的结果并通过增加数组索引计数器来显示它?
我有这段代码,它允许输入从 6 到 11 的数字,并生成 2 个表,如果可能的话,将数字平分。它会生成递增的团队名称(例如团队 1、团队 2、...)。我尝试使用循环来显示我的数据库中的真实团队名称,但它也会循环生成表并创建这么多表。请帮助。
<?php
$count = count($result);
$team = $count;
$teamctr = 1;
if ($team > 5 && $team <= 11){
$table = 2;
$tblctr = 1;
$r1ctr = 0;
$r2ctr = 0;
if ($team == 6){
$row1 = 3;
$row2 = 3;
}
else if ($team == 7){
$row1 = 3;
$row2 = 4;
}
else if ($team == 8){
$row1 = 4;
$row2 = 4;
}
else if ($team == 9){
$row1 = 4;
$row2 = 5;
}
else if ($team == 10){
$row1 = 5;
$row2 = 5;
}
else if ($team == 11){
$row1 = 5;
$row2 = 6;
}
while($tblctr <= $table){$i = 0;
echo "Number of Teams: ".$team; ?><br><?php
echo "Group Into: ".$table; ?><br><?php
?>
<table border="1" align="center" width="30%">
<tr>
<th width="80%" align="center">Group   <?php echo $tblctr; ?></th>
<th width="10%" align="center">W</th>
<th width="10%" align="center">L</th>
</tr>
<?php
if($tblctr = 1){
while($r1ctr < $row1){
?>
<tr>
<td>Team   <?php echo $teamctr ?></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<?php
$r1ctr++;
$teamctr++;
}
echo ""; ?><br><?php
}
if($tblctr = 2){
?>
<table border="1" align="center" width="30%">
<tr>
<th width="80%" align="center">Group   <?php echo $tblctr; ?></th>
<th width="10%" align="center">W</th>
<th width="10%" align="center">L</th>
</tr>
<?php
while($r2ctr < $row2){
?>
<tr>
<td>Team   <?php echo $teamctr ?></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<?php
$r2ctr++;
$teamctr++;
}
echo ""; ?><br><?php
}
else{
echo "Done IF";
}
$tblctr++;
}
}
如何使用此查询显示数据库中的团队名称?
$query = "SELECT * From tbl_teams";
$result = mysql_query($query);
if($result) {
$i = 0;
while ($row = mysql_fetch_array($result)) {
$id[$i] = $row['team_name'];
echo $id[$i];
}
}