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 VB.NET2022如何生成发布成exe文件
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印