Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何动态增加所选区域数_Php_Mysql_Mysqli - Fatal编程技术网

Php 如何动态增加所选区域数

Php 如何动态增加所选区域数,php,mysql,mysqli,Php,Mysql,Mysqli,我的代码: while($row = mysqli_fetch_assoc($result)){ $fullname = $row['full_name']; $roll = $row['roll']; $s_result = $row['result']; $gm = $row['gm']; echo "<tr>"; echo "<th scope='row'>1</th>"; echo "<t

我的代码:

while($row = mysqli_fetch_assoc($result)){
    $fullname = $row['full_name'];
    $roll = $row['roll'];
    $s_result = $row['result'];
    $gm = $row['gm'];

    echo "<tr>";
    echo "<th scope='row'>1</th>";
    echo "<td>{$fullname}</td>";
    echo "<td>{$roll}</td>";
    echo "<td>{$s_result}</td>";
    echo "<td>$gm</td>";
    echo "</tr>";

}
while($row=mysqli\u fetch\u assoc($result)){
$fullname=$row['full_name'];
$roll=$row['roll'];
$s_result=$row['result'];
$gm=$row['gm'];
回声“;
回声“1”;
回显“{$fullname}”;
回音“{$roll}”;
回显“{$s_result}”;
回声“$gm”;
回声“;
}


我想增加所选的数字。现在它是硬编码的。如何动态增加该数字?如果我输入更多数据,则我希望该数字将自动增加。

您只需做一点添加:

$counter = 1; // set a counter
while($row = mysqli_fetch_assoc($result)){
    $fullname = $row['full_name'];
    $roll = $row['roll'];
    $s_result = $row['result'];
    $gm = $row['gm'];

    echo "<tr>";
    echo "<th scope='row'>$counter</th>"; // use the counter
    echo "<td>{$fullname}</td>";
    echo "<td>{$roll}</td>";
    echo "<td>{$s_result}</td>";
    echo "<td>$gm</td>";
    echo "</tr>";
    $counter++; // increase the counter
}
$counter=1;//设置计数器
while($row=mysqli\u fetch\u assoc($result)){
$fullname=$row['full_name'];
$roll=$row['roll'];
$s_result=$row['result'];
$gm=$row['gm'];
回声“;
echo“$counter”;//使用计数器
回显“{$fullname}”;
回音“{$roll}”;
回显“{$s_result}”;
回声“$gm”;
回声“;
$counter++;//增加计数器
}

您需要在
上取一个全局变量,同时
循环并将其初始化为
1
,然后按原样打印并在每次迭代时增加,它将以序列号打印

$index = 1;
while($row = mysqli_fetch_assoc($result)){
    $fullname = $row['full_name'];
    $roll = $row['roll'];
    $s_result = $row['result'];
    $gm = $row['gm'];

    echo "<tr>";
    echo "<th scope='row'>$index</th>";
    echo "<td>{$fullname}</td>";
    echo "<td>{$roll}</td>";
    echo "<td>{$s_result}</td>";
    echo "<td>$gm</td>";
    echo "</tr>";

    $index = $index + 1;
}
$index=1;
while($row=mysqli\u fetch\u assoc($result)){
$fullname=$row['full_name'];
$roll=$row['roll'];
$s_result=$row['result'];
$gm=$row['gm'];
回声“;
回显“$index”;
回显“{$fullname}”;
回音“{$roll}”;
回显“{$s_result}”;
回声“$gm”;
回声“;
$index=$index+1;
}

您没有自动递增的列吗?这将更容易,并使用变量动态地回显id。你的问题有点不清楚,查询是什么样子的。我对列表进行了排序。所以id是随机的。如果是随机的,你可以随时按顺序。从他的评论中,我怀疑顺序是故意的,因此id是随机的。Moumita为什么不直接使用计数器($i=1,然后是$i++)?$query=“按结果描述从计算机订单中选择*”;我按订单做