Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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 - Fatal编程技术网

Php 在一个环路内只回响一次

Php 在一个环路内只回响一次,php,Php,我有一点困惑,我无法解开。我有动态表循环: echo "<table border='1' padding='2' cellspacing='0' "; echo "<tr> <th>ID</th> <th>Producto</th> <th>Ud/Caja</th> <th>Formato</th> <th>Cajas</th> <th>Sue

我有一点困惑,我无法解开。我有动态表循环:

echo "<table border='1' padding='2' cellspacing='0' ";
echo "<tr> <th>ID</th> <th>Producto</th> <th>Ud/Caja</th> <th>Formato</th>  <th>Cajas</th> <th>Sueltas</th> <th>Total</th> </tr>";
// 
while($row = mysql_fetch_array( $result )) {

    // trying to a title line 
    if ($row['proveedor']=="Campocerrado" ) 
    { 

    echo "<tr> <th>TEST</th> <th>TEST</th> <th>TEST</th> <th>TEST</th>  <th>TEST</th> <th>TEST</th> <th>TEST</th> </tr>";


     ;
    ;}

    //

    echo "<tr>";
    echo  "<td>" . $row['idItem'] . "</td>";
    echo '<input type="hidden" name="hiddenidItem[]" id="hiddenField" value="'. $row['idItem'] .'">'; 

    echo "<td>" .  $row['producto'] . "</td>";
    echo '<input type="hidden" name="hiddenProducto[]" id="hiddenField" value="'. $row['producto'] .'">';

    echo '<input type="hidden" name="proveedor[]" id="lastValue" value="'. $row['proveedor'] .'">'; 

    echo "<td>" .  $row['ud/caja'] . "</td>";
    echo '<input type="hidden" name="ud/caja[]" id="hiddenField" value="'. $row['ud/caja'] .'">';

    echo "<td>" .  $row['formato'] . "</td>";
    echo '<input type="hidden" name="formato[]" id="hiddenField" value="'. $row['formato'] .'">';

    echo '<td><input type="number" name="cajas[]" id="cajas[]" value=""></td>';
    echo '<td><input type="number" name="sueltas[]" id="sueltas[]" value=""></td>'; 
    echo '<td><input type="number" name="total[]" id="total" value=""></td>';

    echo '<input type="hidden" name="lastValue[]" id="lastValue" value="'. $row['total'] .'">';  
    echo '<input type="hidden" name="proveedor[]" id="lastValue" value="'. $row['proveedor'] .'">'; 


    echo "</tr>";



 }

echo "</table>";
echo "<br>";

echo”在回答的最简单形式中,使用令牌

$tokenhit = false;
if (!$tokenhit && $row['proveedor']=="Campocerrado" ) { 

   echo "<tr> <th>TEST</th> <th>TEST</th> <th>TEST</th> <th>TEST</th>  
   <th>TEST</th> <th>TEST</th> <th>TEST</th> </tr>";

   $tokenhit = true;


}
$tokenhit=false;
如果(!$tokenhit&&$row['proveedor']==“Campocerrado”){
“回声”测试
“测试”;
$tokenhit=true;
}

但我不确定这是否回答了您的真实问题。

设置一个标志,表明您已经输出了额外的行:

$show_extra_row = true;
while(...) {
   if (($row['proveedor']=="Campocerrado" ) && $show_extra_row) {
       $show_extra_row = false;
       echo ...
   }
}

第一次显示后,标志变为false,额外的行将不再输出。

您可以使用一个临时变量来检查之前是否已满足条件

$firstTime = true;
while($row = mysql_fetch_array( $result )) {

    // trying to a title line 
    if ($firstTime && $row['proveedor']=="Campocerrado" ) 
    { 
        echo "<tr> <th>TEST</th> <th>TEST</th> <th>TEST</th> <th>TEST</th>  <th>TEST</th<th>TEST</th> <th>TEST</th> </tr>";
        $firstTime = false;
    }
    ...
}
$firstTime=true;
while($row=mysql\u fetch\u数组($result)){
//试图删除标题行
如果($firstTime&&$row['proveedor']==“Campocerrado”)
{ 

echo“如果你正确地实现了它,那么这是不可能的。你能用你的新代码更新你的原始问题吗?你确定要把“$tokenhit=false;”在while循环开始之前?不要使用
!$tokenhit
而是使用
$tokenhit!==true
是的,就是这样!它的答案和Daniels一样非常相似,所以你们都应该得到一分。非常感谢!子问题,因为现在我有不同的问题。每当“$row['proveedor']”时,我需要额外的一行满足不同的要求,但它仅为列表中的第一个值显示额外的行,而不是为每个提供程序显示。然后使用状态机:从每行保存Proveeder。如果存储的值不同于当前值,则您已更改Proveeder并输出额外的行。基本上:
if(最后一行的PROVEDEOR!=当前行的PROVEDEOR){output extra line}
$firstTime = true;
while($row = mysql_fetch_array( $result )) {

    // trying to a title line 
    if ($firstTime && $row['proveedor']=="Campocerrado" ) 
    { 
        echo "<tr> <th>TEST</th> <th>TEST</th> <th>TEST</th> <th>TEST</th>  <th>TEST</th<th>TEST</th> <th>TEST</th> </tr>";
        $firstTime = false;
    }
    ...
}