我的代码在do while中使用7个变量,每次do while循环时都会更改 我想替换7个变量而不创建全新的变量,因此每个变量仅显示一次且没有更多变量,我希望变量在每次while循环后都会更改,并且在显示新变量之前会有一个小的延迟
<html>
<body>
<?php
include('connection.php');//connection to databse
$sql = "select COUNT(*)from dbo.arrivals";//getting number of rows from database
$max;
$stmt = sqlsrv_query( $conn, $sql);
sqlsrv_fetch($stmt);
$max= sqlsrv_get_field( $stmt,0 );
$var= array();
$counter=0;
for($i=0;$i<=$max;$i++)
{
$sql = "WITH NthRowCTE AS(SELECT ROW_NUMBER() OVER (ORDER BY ArrivalTime)AS RNum, * FROM dbo.arrivals) SELECT * FROM NthRowCTE WHERE RNum =".$i;
$stmt = sqlsrv_query( $conn, $sql);
sqlsrv_fetch($stmt);
$flight = sqlsrv_get_field( $stmt,3 );
array_push($var,"$flight");
}
$f= array("","","","","","","");
$counter=0;
$range=7;
do{
$f[0]="empty";
$f[1]="empty";
$f[2]="empty";
$f[3]="empty";
$f[4]="empty";
$f[5]="empty";
$f[6]="empty";
if($counter==$range)
{
$range=$range+7;
}
for($i=0;$i<7;$i++)
{
$counter++;
//$i=$counter-1;
if($counter<=$max)
{
$f[$i]= $var[$counter];
}
else
{
$counter=$max;
break;
}
}
echo "<br />";
echo "<br />";
echo $f[0];
echo "<br />";
echo $f[1];
echo "<br />";
echo $f[2];
echo "<br />";
echo $f[3];
echo "<br />";
echo $f[4];
echo "<br />";
echo $f[5];
echo "<br />";
echo $f[6];
echo "<br />";
}
while($counter!=$max);
?>
</body>
</html>