我目前正在使用包含以下表结构的数据库:
round | current
===============
P | 0
1 | 1
2 | 0
3 | 0
4 | 0
A | 0
Run Code Online (Sandbox Code Playgroud)
我一直在尝试编写PHP代码,它将为当前为1的每一行输出"一个点亮的圆圈".因此,根据上表,1将被点亮,因为当前为1 - 其他轮次将由灰色圆圈表示.
我在这里列举了一个例子:http://i.imgur.com/GYvUdii.png
但是我现在遇到的困难是我的代码输出了这个:http://i.imgur.com/Q41kBnM.png,当它只是意味着返回如上所述的单行时.
我在这里包含了HTML输出:http://jsfiddle.net/pn8BW/
这是我现在使用的PHP/MySQL.希望得到一些帮助,因为我已经在它工作了一个小时:-(:
<?php
$sql = "SELECT * from ts_rounds";
$result = $pdo->query($sql);
$circleSize = array ('circle_small', 'circle');
$rounds = '';
foreach ($result as $row) {
switch ($row['round']) {
case 'P':
$rounds .= '<div id="r0" class="'.$circleSize[$row['current']].'"><h3>P</h3></div>';
case '1':
$rounds .= '<div id="r1" class="'.$circleSize[$row['current']].'"><h3>1</h3></div>';
case '2':
$rounds .= '<div id="r2" class="'.$circleSize[$row['current']].'"><h3>2</h3></div>';
case '3':
$rounds .= '<div id="r3" class="'.$circleSize[$row['current']].'"><h3>3</h3></div>';
case '4':
$rounds .= '<div id="r4" class="'.$circleSize[$row['current']].'"><h3>4</h3></div>';
case 'A':
$rounds .= '<div id="r5" class="'.$circleSize[$row['current']].'"><h3>A</h3></div>';
}
}
echo $rounds;
?>
Run Code Online (Sandbox Code Playgroud)
你忘记break;了switch:
case 'P':
$rounds .= '<div id="r0" class="'.$circleSize[$row['current']].'"><h3>P</h3></div>';
break;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29 次 |
| 最近记录: |