PHP中的Css百分比值

时间:2016-04-25 10:25:43

标签: php html css

我正在尝试将结果显示为百分比栏(css),我从$row['Balai']获取mysql query,然后计算$proc,我设置$sum同样。它工作正常,但不是得到不同的inner值(条)我总是得到相同的,所有的条看起来都一样

while($row=$list->fetch_assoc()){
    $proc = round((($row['Balai'] / $sum) * 100),1); ?>
    <style type="text/CSS">
    .outter{
    height 25px;
    width:500px;
    border-right:solid 1px #000;
    background-color: red;
    }
    .inner{
    height:25px;
    width: <?php echo $proc ?>%;
    border-right:solid 1px #000;
    background-color:lightblue;
    </style>
    <tr>
    <center>
    <?php
    echo "<td>" . $row['ID'] . "</td><td>" . $row['Vardas'] . "</td><td>" . $row['Pavarde'] . "</td><td>" . $row['Balai'] . "<td>"; ?>
    <div class="outter">
    <div class='inner'><?php echo $proc ?>%</div>
    <?php
    echo "</td><br />";
    echo "</center>";
    echo "</tr>";
    $x++;
    }
    echo "</table>";
    echo "<b>100% sudaro: " . $sum . "</b>";

1 个答案:

答案 0 :(得分:0)

试试这个:(请确保$proc的值不同)

 <style type="text/CSS">
        .outter{
        height 25px;
        width:500px;
        border-right:solid 1px #000;
        background-color: red;
        }
        .inner{
        height:25px;       
        border-right:solid 1px #000;
        background-color:lightblue;
        </style>
  <?php  
    while($row=$list->fetch_assoc()){
        $proc = round((($row['Balai'] / $sum) * 100),1); ?>

        <tr>
        <center>
        <?php
        echo "<td>" . $row['ID'] . "</td><td>" . $row['Vardas'] . "</td><td>" . $row['Pavarde'] . "</td><td>" . $row['Balai'] . "<td>"; ?>
        <div class="outter">
        <div class='inner' style='width: "<?php echo $proc ?>"%'><?php echo $proc ?>%</div>
        <?php
        echo "</td><br />";
        echo "</center>";
        echo "</tr>";
        $x++;
        }
        echo "</table>";
        echo "<b>100% sudaro: " . $sum . "</b>";