是否可以在php中不循环地显示mysql查询的结果?
是否可以使用包含mysql查询结果的数组,并通过增加数组索引计数器来显示结果? 我有一个代码,允许从6到11的数字输入并生成 如果可能,将数字等分的两个表。它生成 增加的团队名称(例如团队1、团队2等)。我试着使用一个循环 显示数据库中的真实团队名称,但它会循环 表的生成也会创建很多表。请帮助是否可以在php中不循环地显示mysql查询的结果?,php,html,mysql,sql,Php,Html,Mysql,Sql,是否可以使用包含mysql查询结果的数组,并通过增加数组索引计数器来显示结果? 我有一个代码,允许从6到11的数字输入并生成 如果可能,将数字等分的两个表。它生成 增加的团队名称(例如团队1、团队2等)。我试着使用一个循环 显示数据库中的真实团队名称,但它会循环 表的生成也会创建很多表。请帮助 <?php $count = count($result); $team = $count; $teamctr = 1; if (
<?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++;
}
}
在数据库查询循环中,尝试更改为
$team_names = array();
while ($row = mysql_fetch_array($result)) {
$team_names[] = $row['team_name'];
}
然后在表代码中,尝试将其更改为
$count = count($team_names);
$team = $count;
$teamctr = 0;
及
团队
你的问题毫无意义。如果你增加一个计数器,那么你基本上是在使用一个循环。您只是构造了一个错误的循环。您没有将整个表放入循环中,只有实际的数据输出内容。
和
业务超出了循环。不,不可能。另外,做$i++;在您的while中,我需要在循环中放入,因为我的代码生成了两个表。请试试我的代码。对不起,我是这方面的新手,请帮助我编辑代码,将团队名称从数据库更改为实际团队名称。Team @James因为您是新手,所以应该学习用PHP访问数据库的正确方法,而不是使用mysql.*
函数。学习mysqli或PDO。此外,请确保您掌握了循环结构的概念。如果由于循环而输出所需的mor HTML元素,那么只需将不需要的元素移出循环即可。
$count = count($team_names);
$team = $count;
$teamctr = 0;
<td>Team   <?php echo $team_names[$teamctr]; ?></td>