我在用PHP制作'计数'系统时遇到了麻烦。我希望它是这样的:
我的问题是我无法做到这一点,因为名字是通过一个while循环来的,所以我现在不知道如何制作它。我的代码如下:
<?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
}
?>
所以我的问题是如何制作一个数到100的计数系统?它需要先行。
抱歉英文不好,谢谢你的帮助!
答案 0 :(得分:5)
您可以尝试这样的事情:
<?php
$counter = 0;
while($score = $highscore->fetch_array())
{
$counter++;
//Your content
if ( $counter >= 100 ) {
break;
}
}
当它达到100时,这会打破你的时间。