我正在制作从在线@数据库填充绿色“行”的面板。 这是用于绘制所有内容的CSS,不会导致任何错误。
<style>
.one {
width: 1px;
height: 12px;
display:block;
float:left;
background-color: green;
}
.three {
width: 3px;
height: 12px;
display:block;
float:left;
background-color: green;
}
.five {
width: 5px;
height: 12px;
display:block;
float:left;
background-color: green;
}
.ten {
width: 10px;
height: 12px;
display:block;
float:left;
background-color: green;
.thirty {
width: 30px;
height: 12px;
display:block;
float:left;
background-color: green;
}
.fifty {
width: 30px;
height: 12px;
display:block;
float:left;
background-color: green;
}
</style>
还有连接到sql的PHP代码..检查玩家并绘制css。
<?php
define('mySQL_hostname', 'IP'); //
define('mySQL_database', 'DB'); //
define('mySQL_username', 'US'); //
define('mySQL_password', 'PW'); //
//connects to mysql
$db_link = mysql_connect( mySQL_hostname, mySQL_username, mySQL_password )
or print( 'SQL_CE' );
//connects to Db
$db_select = mysql_select_db( mySQL_database, $db_link )
or print("SQL_DB");
//selects table
$chars= mysql_query("SELECT `online` FROM `users` where `online`=1");
$rows = mysql_num_rows($chars);
// $rows = counted players... which prints out number.
if ($rows <= 1) {
print '<span class="one"></span>';
}
else if ($rows >= 50) {
print '<span class="three"></span>';
}
else if ($rows >= 150) {
print '<span class="ten"></span>';
}
else if ($rows >= 300) {
print '<span class="ten"></span>';
print '<span class="ten"></span>';
}
else if ($rows >= 500) {
print '<span class="thirty"></span>';
print '<span class="one"></span>';
}
else if ($rows >= 700) {
print '<span class="ten"></span>';
print '<span class="thirty"></span>';
print '<span class="three"></span>';
}
else if ($rows >= 900) {
print '<span class="ten"></span>';
print '<span class="five"></span>';
print '<span class="thirty"></span>';
}
else if ($rows >= 1000) {
print '<span class="thirty"></span>';
print '<span class="thirty"></span>';
print '<span class="three"></span>';
}
else if ($rows >= 1200) {
print '<span class="fifty"></span>';
print '<span class="ten"></span>';
print '<span class="ten"></span>';
print '<span class="five"></span>';
}
else if ($rows >= 1400) {
print '<span class="fifty"></span>';
print '<span class="thirty"></span>';
print '<span class="five"></span>';
}
else if ($rows >= 1600) {
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
}
else if ($rows >= 1800) {
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
print '<span class="ten"></span>';
}
else if ($rows >= 2000) {
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
print '<span class="thirty"></span>';
}
else if ($rows >= 2200) {
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
print '<span class="thirty"></span>';
print '<span class="ten"></span>';
}
else if ($rows >= 2500) {
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
print '<span class="fifty"></span>';
}
else {
echo "Script error"; // this place i got printed out.
}
?>
所以我得到的是......来自doc底部的“脚本错误”。我拼错了什么或什么?
答案 0 :(得分:1)
一旦变量$rows
变为{1}但是小于50,那么代码最初构成的方式就没有条件匹配 - 因此跳过错误。我认为它应该更像是:
if( $rows <= 1 ) {
echo '<span class="one"></span>';
} elseif( $rows > 1 && $rows < 50 ) {
echo '<span class="one"></span>';
} elseif( $rows >= 50 && $rows < 150 ) {
echo '<span class="three"></span>';
} elseif( $rows >= 150 && $rows < 300 ) {
echo '<span class="ten"></span>';
} elseif( $rows >= 300 && $rows < 500 ) {
echo '
<span class="ten"></span>
<span class="ten"></span>';
} elseif( $rows >= 500 && $rows < 700 ) {
echo '
<span class="thirty"></span>
<span class="one"></span>';
} elseif( $rows >= 700 && $rows < 900 ) {
echo '
<span class="ten"></span>
<span class="thirty"></span>
<span class="three"></span>';
} elseif( $rows >= 900 && $rows < 1000 ) {
echo '
<span class="ten"></span>
<span class="five"></span>
<span class="thirty"></span>';
} elseif( $rows >= 1000 && $rows < 1200 ) {
echo '
<span class="thirty"></span>
<span class="thirty"></span>
<span class="three"></span>';
} elseif( $rows >= 1200 && $rows < 1400 ) {
echo '
<span class="fifty"></span>
<span class="ten"></span>
<span class="ten"></span>
<span class="five"></span>';
} elseif( $rows >= 1400 && $rows < 1600 ) {
echo '
<span class="fifty"></span>
<span class="thirty"></span>
<span class="five"></span>';
} elseif( $rows >= 1600 && $rows < 1800 ) {
echo '
<span class="fifty"></span>
<span class="fifty"></span>';
} elseif( $rows >= 1800 && $rows < 2000 ) {
echo '
<span class="fifty"></span>
<span class="fifty"></span>
<span class="ten"></span>';
} elseif( $rows >= 2000 && $rows < 2200 ) {
echo '
<span class="fifty"></span>
<span class="fifty"></span>
<span class="thirty"></span>';
} elseif( $rows >= 2200 && $rows < 2500 ) {
echo '
<span class="fifty"></span>
<span class="fifty"></span>
<span class="thirty"></span>
<span class="ten"></span>';
} elseif( $rows >= 2500) {
echo '
<span class="fifty"></span>
<span class="fifty"></span>
<span class="fifty"></span>';
} else {
echo "Script error";
}
那就是说,你考虑过meter
标签吗?它似乎是理想的目的,需要更少的标记,所有计算都在内部完成?
即:
<meter min='0' max='2500' value='{$rows}'>{$rows}</meter>