Reputation: 17
I'm attempting to format an iframe from urls, heights, widths, etc put in an array. Here is the code I have so far.
<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>
Here is my array from 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'
)
);
My problem is that the loop is only pulling either the first value from the array when inside the loop and only the last value if its placed outside the loop brackets as shown below. I am attempting to format multiple urls from the array items and have them placed in an iframe horizontal to eachother. Is there something I'm doing wrong?
Edited to add full code, including html divs.
Just moved everything to dashlets.php as suggested. I'm still only getting a return result from the first array item.
<?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";
}
and in my main.php, which is viewable from my index.php viewport.
<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>
Upvotes: 0
Views: 42
Reputation: 2442
I just try your code, just added into the dashlets.php:
<?php
$dl = array(
'dashlet1' => array(
'url' => 'http://1.1.1.1:3333/stuff/stuff?36',
'height' => '200',
'width' => '450'
),
'dashlet2' => array(
'url' => 'http://1.1.1.1:3333/stuff/stuff?37',
'height' => '200',
'width' => '450'
......
......
'width' => '450'
),
'dashlet8' =>array(
'url' => 'http://1.1.1.1:3333/stuff/stuff?35',
'height' => '200',
'width' => '350'
)
);
?>
And put the echo inside the loop:
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>" . "\n";
}
And got this:
<iframe src="http://1.1.1.1:3333/stuff/stuff?36" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?37" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?311" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?34" height="200" width="350" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?38" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?310" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?33" height="200" width="450" frameborder="0"> <\iframe>
<iframe src="http://1.1.1.1:3333/stuff/stuff?35" height="200" width="350" frameborder="0"> <\iframe>
Upvotes: 1