簡體   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