dongshuzhuo5659 2014-05-08 16:23
浏览 94
已采纳

当计数器达到一定数量时停止while循环

I'm having trouble to make a 'counting' system in PHP. I would like it to be like this:

  1. Clark
  2. Maikel
  3. Steven
  4. .....

My problem is that I can't make this because the names are coming through a while loop, so I don't know how to make it now. My code is as follows:

<?php
    while($score = $highscore->fetch_array())
    {
        // Systeem voor levels.
        if($score['clicks'] >= 0 && $score['clicks'] <= 49)
        {
            $level = 'Level 1';
        }
        elseif($score['clicks'] >= 50 && $score['clicks'] <= 99)
        {
            $level = 'Level 2';
        }
        else if($score['clicks'] >= 100 && $score['clicks'] <= 199)
        {
            $level = 'Level 3';
        }
        else if($score['clicks'] >= 200 && $score['clicks'] <= 349)
        {
            $level = 'Level 4';
        }
        else if($score['clicks'] >= 350 && $score['clicks'] <= 499)
        {
            $level = 'Level 5';
        }
        else if($score['clicks'] >= 500 && $score['clicks'] <= 749)
        {
            $level = 'Level 6';
        }
        else if($score['clicks'] >= 750 && $score['clicks'] <= 999)
        {
            $level = 'Level 7';
        }
        else if($score['clicks'] >= 1000 && $score['clicks'] <= 1499)
        {
            $level = 'Level 8';
        }
        else if($score['clicks'] >= 1500 && $score['clicks'] <= 1999)
        {
             $level = 'Level 9';
        }
        else if($score['clicks'] >= 2000 && $score['clicks'] <= 2999)
        {
             $level = 'Level 10';
        }
        else if($score['clicks'] == 3000)
        {
             $level = 'Level 11';
        }
        else if($score['clicks']> 3000)
        {
             $level= 'Level ' . floor(($score['clicks']/1000)+8);
        }
    ?>
    <tr>
      <td><?php echo $score['name']; ?></td>
      <td><?php echo $score['clicks']; ?></td>
      <td><?php echo $level; ?></td>
    </tr>
    <?php
    }
    ?>

So my question is how can I make a counting system that count up till 100? It needs to go before .

Sorry for the bad English, thank you for helping!

  • 写回答

1条回答 默认 最新

  • dongyu2300 2014-05-08 16:43
    关注

    You can try something like this:

    <?php
        $counter = 0;
        while($score = $highscore->fetch_array())
        {
            $counter++;
    
            //Your content
    
            if ( $counter >= 100 ) {
                break;
            }
        }
    

    This should break your while when it reaches 100.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection