我試圖格式化從網址,高度,寬度等放入數組中的iframe。這是我迄今爲止的代碼。從關聯數組中格式化URL
<div class="row"
<div class="col-md-6">
<div class="info-box twitter-bg">
<div>
<?php
if ($cfg_array['grafana'] == 'true') {
include 'dashlets.php';
foreach ($dl as $element) {
$url = $element["url"];
$height = $element["height"];
$width = $element["width"];
echo "<iframe src=\"" . $url . " \"" . "height=\"" . $height . " \"" . "width=\"" . $width . " \"" . "frameborder=\"0\">" . " " . "<\iframe>" . " ";
}
}
?>
</div>
</div>
</div>
這是我的dashlets.php數組。
<?php
$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'
)
);
我的問題是環路只從陣列環路和僅最後值內部時拉動所述第一值,如果其放置在環路括號外,如下所示。 我試圖格式化多個從陣列項目的網址,並將它們放置在一個iframe水平對彼此。 有什麼我做錯了嗎?
編輯添加完整的代碼,包括html divs。
剛纔將所有內容都移到了dashlets.php中,正如所建議的那樣。我仍然只從第一個數組項返回結果。
<?php
/*
* 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";
}
和在我的main.php中,這是從我的index.php視口可查看。
<div class="row"
<div class="col-md-6">
<div class="info-box twitter-bg">
<div>
<?php
if ($cfg_array['grafana'] == 'true') {
include 'dashlets.php';
}
?>
</div>
</div>
</div>
您想成爲PHP代碼的結果? –