【问题标题】:Issues with associative array and formatting关联数组和格式的问题
【发布时间】:2017-02-21 03:50:16
【问题描述】:

我一直在尝试使用 grafana 嵌入式图表创建仪表板。我在格式化它们时遇到了一些问题,我认为这是我编码不正确的问题,但是在调查并在这里创建了一篇关于它的不同帖子之后,我已经确认这应该并且确实正确输出了我的所有 dashlets。我的问题是它没有显示它们,而是只显示数组中的第一个。

我的代码:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$dl = array
(
    'dashlet1' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet2' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet3' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet4' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4',
        'height' => '200',
        'width' => '350'
    ),
    'dashlet5' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet6' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet7' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet8' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5',
        'height' => '200',
        'width' => '350'
    )
);
foreach ($dl as $element) {
    $url = $element["url"];
    $height = $element["height"];
    $width = $element["width"];

    echo "<iframe src=\"" . $url . "\"" . " height=\"" . $height . "\" " . "width=\"" . $width . "\"" . " frameborder=\"0\">" . " " . "<\iframe>" . "\n";

我的输出:

<iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6" height="200" width="450" frameborder="0"> &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4" height="200" width="350" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5" height="200" width="350" frameborder="0"&gt; &lt;\iframe&gt;
</iframe>

What I see

【问题讨论】:

  • &lt;\iframe&gt; 应该使用/ 作为&lt;/iframe&gt;。可能是问题。
  • 无论您使用什么来显示输出似乎都是 html 编码后续数据行,因为它将它们放在第一个 iFrame 中而不是创建新的。显示这个的代码是什么?
  • 显示所有代码..您提供的部分还不够..

标签: php html arrays


【解决方案1】:

检查修改后的foreach循环:

foreach ($dl as $element) {
    $url = $element["url"];
    $height = $element["height"];
    $width = $element["width"];

    echo "<iframe src=\"{$url}\" height=\"{$height}\" width=\"{$width}\" frameborder=\"0\"></iframe>\n";
} 

【讨论】:

  • 那么您能否将此答案标记为已批准?
  • 完成,抱歉耽搁了。
猜你喜欢
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多