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
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度