向变量满足条件的行添加不同的类/样式

时间:2014-01-15 14:31:46

标签: mysql styles row echo

问题是所有图像都以不透明度显示:0.4。我需要不同的样式到每行,​​从数字列的值小于100。

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
        {       
            $progres = $row['number'];
            $num_rows++;    
            echo "$progres <br/>";
            echo "<div class='right_achiev'>";
            echo '<div id="box1" class="box">'; 
            echo '<span class="caption simple-caption">';
            echo '<p class="sq1">'.$row['name'].'</p>';
            echo '<p class="unlok">UNLOCKED:<br/> 2014-01-09 16:25 </p>';
            echo '</span>';

            if ($progres < 100)
            {
                echo "<img class='achiev_icon' src='".$row['icon']."'/>";   
            }
            else 
            {
                echo "<img class='achiev_icon' style='opacity:0.4' src='".$row['icon']."'/>";   
            }

            echo "</div>";  
            echo "</div>";  
        }

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此代码

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {       
        $progres = intval($row['number']);
        $num_rows++;    
        echo "$progres <br/>";
        echo "<div class='right_achiev'>";
        echo '<div id="box1" class="box">'; 
        echo '<span class="caption simple-caption">';
        echo '<p class="sq1">'.$row['name'].'</p>';
        echo '<p class="unlok">UNLOCKED:<br/> 2014-01-09 16:25 </p>';
        echo '</span>';

        if ($progres < 100)
        {
            echo "<img class='achiev_icon' src='".$row['icon']."'/>";   
        }
        else 
        {
            echo "<img class='achiev_icon' style='opacity:0.4' src='".$row['icon']."'/>";   
        }

        echo "</div>";  
        echo "</div>";  
    }