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.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题