douxianglu4370 2019-04-01 17:36
浏览 57
已采纳

从函数中回显PHP变量宽度:样式

I need to get the variable $percent_format outside of the loop for usage in my style to get the dynamical width für the div. But the Problem is i parameterized the funcion Ofen_Auslastung with a sql result from the Loop. Any idea how to fix this?

foreach ($connection->query($sql) as $row) {

                        $j=0;
                        echo "<tr>";
                            echo "<td> <a href='Kapauebersicht.php?OfenName=".$row['Name']."'><button onclick='myFunction()'><img src='http://xxx/xxx/Bilder/".$row[$j].".png' height='80px'></button></a></td>";       //Bezeichnung1
                            echo "<td>".$row[$j]."</td>";       //Bezeichnung1
                            list($total, $percent_format, $Anzahl) = Ofen_Auslastung($row[$j]);
                            $j++;
                            echo "<td>".$row[$j]."</td>";       //Bezeichnung2
                            $j++;
                            echo "<td>".$row[$j]."</td>";       //Bezeichnung3
                            $j++;
                            echo "<td><div class='outter'><div class='inner' >$percent_format%</div> $Anzahl belegte Plätze sind $percent_format% Auslastung von $total Plätzen. <p /></td>";
                        echo "</tr>";
                    }

                $connection = null; //reset connection


            }
            catch(PDOException $e)
                {
                    echo $e->getMessage();
                }           
    echo "</table>";

            //echo "<pre>";
            //print_r($sort);
            //echo " ****************************************************************** <br>";
            //print_r($sorted);

            //echo "</pre>";

            ?>

</table>
<button  value="Zurück" class="Button3" onclick="location.href='ma_QualiOverview.php'">Zurück</button>
<style type="text/css">
.outter{
    height:25px;
    width: 200px;
    border:solid 1px #000;
}
.inner{
    height:25px;
    width:<?php echo $percent_format ?>%;
    border-right:solid 1px #000;
    background: rgb(30,87,153); /* Old browsers */
background: -moz-linear-gradient(top, rgba(30,87,153,1) 0%, rgba(41,137,216,1) 50%, rgba(32,124,202,1) 51%, rgba(125,185,232,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(30,87,153,1) 0%,rgba(41,137,216,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(30,87,153,1) 0%,rgba(41,137,216,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );
}
</style>

thx for your help.

  • 写回答

3条回答 默认 最新

  • doushou7169 2019-04-01 18:14
    关注

    I think you are trying to add dynamic width in the element div with class named inner. According to me you doesn't need variable $percent_format value outside the loop if you want to change the style css of the element div dynamically, which is already inside the loop. You just need to add inline css in div with class named inner like the code line in bold written below:

    foreach ($connection->query($sql) as $row) {
      $j=0;
      echo "<tr>";
      echo "<td> <a href='Kapauebersicht.php?OfenName=".$row['Name']."'><button onclick='myFunction()'><img src='http://xxx/xxx/Bilder/".$row[$j].".png' height='80px'></button></a></td>";       //Bezeichnung1
      echo "<td>".$row[$j]."</td>";       //Bezeichnung1
      list($total, $percent_format, $Anzahl) = Ofen_Auslastung($row[$j]);
      $j++;
      echo "<td>".$row[$j]."</td>";       //Bezeichnung2
      $j++;
      echo "<td>".$row[$j]."</td>";       //Bezeichnung3
      $j++;
      echo "<td><div class='outter'><div class='inner' style='width: $percent_format%;'>$percent_format%</div> $Anzahl belegte Plätze sind $percent_format% Auslastung von $total Plätzen. <p /></td>";
      echo "</tr>";
    }
    

    You doesn't need to call the variable $percent_format outside the foreach for this. And if you still want to call the variable outside the loop, you can use it. But doing so will only display the last item's value from the loop. I hope this might solve your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog