循环 - 可能只有6个循环?

Cec*_*uez 1 php while-loop

这是我的代码,我希望它只能执行前6个数组项.另外,如何在6个第一个数组项之后为所有内容编写循环?

while ($servdescarrayrow = mysql_fetch_array("servdescarray")) {

    ECHO "<fieldset>Services: ".$servdescarrayrow."</fieldset>";
}
Run Code Online (Sandbox Code Playgroud)

MrJ*_*MrJ 6

请在第一次请求时尝试以下操作:

$count = 0;
while($servdescarrayrow = mysql_fetch_array("servdescarray")) {
  $count++;
  echo "<fieldset>Services: ".$servdescarrayrow."</fieldset>";
  if($count == 6){
    break;
  }
}
Run Code Online (Sandbox Code Playgroud)

然后你可以在下面做第2部分:

$count = 0;
while($servdescarrayrow = mysql_fetch_array("servdescarray")) {
  $count++;
  if($count > 6){
    echo "<fieldset>Services: ".$servdescarrayrow."</fieldset>";
  }
}
Run Code Online (Sandbox Code Playgroud)

或者(并且更好)是LIMIT在您的SQL查询中使用

  • 不要以为你需要一个字符串...数字有什么问题? (5认同)