doudou2121 2014-03-30 14:51 采纳率: 50%
浏览 949
已采纳

while循环有两个条件

This while loop is supposed to continue until the end of the array or until counter reaches 6, what am I doing wrong here?

   while($row = mysql_fetch_array($resultSet, MYSQL_ASSOC) && ($counter < 6))
        {
        ?>

    <?php echo $row['Item_NAME'] ?>

<img style="width:250px; height:250px;" src="<?php {echo "{$row['Item_IMAGE']}";} ?>">

    <?php $counter = $counter + 1;
    ?>
        <?php
        }

Works without the && ($counter < 6)but shows the wrong number of images, adding this will show the correct number of boxes (where the images should be) but not retrieve the images or names from the array. Thanks for any help.

  • 写回答

1条回答 默认 最新

  • dongmao9217 2014-03-30 15:00
    关注

    Couldn't you just use break; inside, when the second condition isn't true anymore?

    while($row = mysql_fetch_array($resultSet, MYSQL_ASSOC))
        {
        if($counter > 5){
            break;
        }
        ?>
    
        <?php echo $row['Item_NAME'] ?>
    
        <img style="width:250px; height:250px;" src="<?php {echo "{$row['Item_IMAGE']}";} ?>">
    
        <?php $counter = $counter + 1;
        ?>
        <?php
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?