繁体   English   中英

PHP For Loop仅运行一次

[英]PHP For Loop only running once

我有一个for循环来遍历和数组,运行与每个元素有关的数据库查询,然后调用一个打印与之相关的东西的函数。 该数组长12个元素,但是for循环永远不会超过元素0。它不会出错或失败,只是在第一个元素之后不执行任何操作。 我通过添加echo $x;验证了这一点echo $x; echo $vendorsname[$x]; 在每个循环周期开始时,请确保仅将0呼出到页面。

$continuetill = count($vendorsname);

for ($x = 0; $x < $continuetill; $x++)
{

echo $x;
echo $vendorsname[$x];

$sql="SELECT low,mid,high,verlow,vermin,verhigh FROM vendors WHERE vendor = ".$x." ORDER BY id DESC LIMIT 1";

if ($result=mysqli_query($conn,$sql))
  {
  // Fetch one and one row
  while ($row=mysqli_fetch_row($result))
    {
      $low = $row[0];
      $mid = $row[1];
      $high = $row[2];
      $verlow = $row[3];
      $vermid = $row[4];
      $verhigh = $row[5];



      if(($low > $mid) && ($low > $high))
      {
        likely295Message($vendorsname[$x]);
      }
      elseif (($high > $low) && ($high > $mid) && ($high < 15))
      {
        possibly300Message($vendorsname[$x]);
      }
      elseif (($high > $low) && ($high > $mid) && ($high >= 15))
      {
        likely300Message($vendorsname[$x]);
      }
      elseif (($mid > $low) && ($mid > $high))
      {
        likely296Message($vendorsname[$x]);

      }else
      {
        unknownMessage($vendorsname[$x]);
      }


      if(($verlow != 0) || ($vermid != 0) || ($verhigh != 0))
      {
        if(($verlow > $vermid) && ($verlow > $verhigh))
        {
          verified295Message($vendorsname[$x]);
          changeBackgroundBack($vendorsname[$x]);
          changeImage($vendorsname[$x]);

        }
        elseif (($verhigh > $verlow) && ($verhigh > $vermid))
        {
          verified300($vendorsname[$x]);
          changeBackground($vendorsname[$x]);
          changeImage($vendorsname[$x]);
        }
        elseif (($vermid > $verlow) && ($vermid > $verhigh))
        {
          verified296($vendorsname[$x]);
          changeBackgroundBack($vendorsname[$x]);
          changeImage($vendorsname[$x]);
        }
      }

    }

  mysqli_free_result($result);
}
}

确保您已打开错误显示。 在脚本的开头添加:

ini_set('display_errors', 1);

以确保您没有任何错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM