Print values from json and html files stored in different folders with variable names

I’m automating some tests, every run generates a folder with a variable name. Inside every one of those folders there’s a “statistics.json” and a “index.html”.
For each folder I need to get some values from both files to populate a table: i used a foreach function but it only gets those values from one folder. I know this because the Start time is exactly the same for each row of the table.

So i have my main path

$path = "/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL";
$scan = scandir($path);

Then I’m creating an array with every folder in the path:

$folder = array();
    foreach($scan as $folders) {
    
    if($folders !== '.' && $folders !== '..'){ 
            $folder[] = $folders;

I do this because then I can create a path using the $folders variable in the middle, like so:

//json path
$path2 = "/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/".$folders."/statistics.json";  
    
//html path
$path4 = "/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/".$folders."/index.html";
    

I know this works because if I echo the values I get:

/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.10-12.03.11/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.10-12.08.06/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.23-15.30.53/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.23-15.48.04/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11_2024.06.30-22.14.24/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11_2024.07.09-12.08.05/statistics.json
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/miao/statistics.json

and

/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.10-12.03.11/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.10-12.08.06/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.23-15.30.53/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11-kibana_2024.07.23-15.48.04/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11_2024.06.30-22.14.24/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/FUC-UBIM11_2024.07.09-12.08.05/index.html
/app/apache-jmeter-5.6.2/TestCri/Performance/fuc/FULL/miao/index.html

Since I am sitll in the foreach function, I now go with

$json = file_get_contents($path2);
$data = (array)json_decode($json);

And I know this works because if i echo $json I get:

{ “Kibana” : { “transaction” : “Kibana”, “sampleCount” : 5,
“errorCount” : 5, “errorPct” : 100.0, “meanResTime” : 31505.8,
“medianResTime” : 31511.0, “minResTime” : 31495.0, “maxResTime” :
31514.0, “pct1ResTime” : 31514.0, “pct2ResTime” : 31514.0, “pct3ResTime” : 31514.0, “throughput” : 0.1586495748191395,
“receivedKBytesPerSec” : 0.6399589196757203, “sentKBytesPerSec” : 0.0
}, “Total” : { “transaction” : “Total”, “sampleCount” : 20,
“errorCount” : 5, “errorPct” : 25.0, “meanResTime” :
7944.549999999999, “medianResTime” : 135.0, “minResTime” : 0.0, “maxResTime” : 31514.0, “pct1ResTime” : 31511.9, “pct2ResTime” :
31513.9, “pct3ResTime” : 31514.0, “throughput” : 0.610016470444702, “receivedKBytesPerSec” : 1.2383215206185567, “sentKBytesPerSec” :
0.07163523493259318 }, “Kibana-0” : { “transaction” : “Kibana-0”, “sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
12.6, “medianResTime” : 20.0, “minResTime” : 0.0, “maxResTime” : 22.0, “pct1ResTime” : 22.0, “pct2ResTime” : 22.0, “pct3ResTime” : 22.0,
“throughput” : 227.27272727272725, “receivedKBytesPerSec” :
276.0120738636364, “sentKBytesPerSec” : 0.0 }, “MT-0” : { “transaction” : “MT-0”, “sampleCount” : 5, “errorCount” : 0,
“errorPct” : 0.0, “meanResTime” : 10.8, “medianResTime” : 9.0,
“minResTime” : 4.0, “maxResTime” : 25.0, “pct1ResTime” : 25.0,
“pct2ResTime” : 25.0, “pct3ResTime” : 25.0, “throughput” :
192.30769230769232, “receivedKBytesPerSec” : 247.67127403846155, “sentKBytesPerSec” : 0.0 }, “MT” : { “transaction” : “MT”,
“sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
249.0, “medianResTime” : 246.0, “minResTime” : 245.0, “maxResTime” : 262.0, “pct1ResTime” : 262.0, “pct2ResTime” : 262.0, “pct3ResTime” : 262.0, “throughput” : 19.083969465648856, “receivedKBytesPerSec” : 30.224982108778626, “sentKBytesPerSec” : 8.964247375954198 } } { “Kibana” : { “transaction” : “Kibana”, “sampleCount” : 5, “errorCount”
: 5, “errorPct” : 100.0, “meanResTime” : 31543.0, “medianResTime” :
31541.0, “minResTime” : 31541.0, “maxResTime” : 31549.0, “pct1ResTime” : 31549.0, “pct2ResTime” : 31549.0, “pct3ResTime” : 31549.0,
“throughput” : 0.1584685598377282, “receivedKBytesPerSec” :
0.6391049398611816, “sentKBytesPerSec” : 0.0 }, “Total” : { “transaction” : “Total”, “sampleCount” : 20, “errorCount” : 5,
“errorPct” : 25.0, “meanResTime” : 7946.349999999999, “medianResTime”
: 121.0, “minResTime” : 1.0, “maxResTime” : 31549.0, “pct1ResTime” :
31542.8, “pct2ResTime” : 31548.7, “pct3ResTime” : 31549.0, “throughput” : 0.6097746882526907, “receivedKBytesPerSec” :
1.237652062562883, “sentKBytesPerSec” : 0.07160684205311138 }, “Kibana-0” : { “transaction” : “Kibana-0”, “sampleCount” : 5,
“errorCount” : 0, “errorPct” : 0.0, “meanResTime” : 4.2,
“medianResTime” : 2.0, “minResTime” : 1.0, “maxResTime” : 13.0,
“pct1ResTime” : 13.0, “pct2ResTime” : 13.0, “pct3ResTime” : 13.0,
“throughput” : 384.61538461538464, “receivedKBytesPerSec” :
466.796875, “sentKBytesPerSec” : 0.0 }, “MT – OK – 1 recipient-0” : { “transaction” : “MT – OK – 1 recipient-0”, “sampleCount” : 5,
“errorCount” : 0, “errorPct” : 0.0, “meanResTime” : 9.2,
“medianResTime” : 8.0, “minResTime” : 3.0, “maxResTime” : 20.0,
“pct1ResTime” : 20.0, “pct2ResTime” : 20.0, “pct3ResTime” : 20.0,
“throughput” : 238.09523809523807, “receivedKBytesPerSec” :
306.6871279761905, “sentKBytesPerSec” : 0.0 }, “MT – OK – 1 recipient” : { “transaction” : “MT – OK – 1 recipient”, “sampleCount” : 5,
“errorCount” : 0, “errorPct” : 0.0, “meanResTime” : 229.0,
“medianResTime” : 228.0, “minResTime” : 222.0, “maxResTime” : 238.0,
“pct1ResTime” : 238.0, “pct2ResTime” : 238.0, “pct3ResTime” : 238.0,
“throughput” : 20.920502092050206, “receivedKBytesPerSec” :
33.13774843096235, “sentKBytesPerSec” : 9.826915533472803 } } { “Kibana” : { “transaction” : “Kibana”, “sampleCount” : 5, “errorCount”
: 5, “errorPct” : 100.0, “meanResTime” : 31633.8, “medianResTime” :
31637.0, “minResTime” : 31628.0, “maxResTime” : 31637.0, “pct1ResTime” : 31637.0, “pct2ResTime” : 31637.0, “pct3ResTime” : 31637.0,
“throughput” : 0.15802281849499067, “receivedKBytesPerSec” :
0.6374307168705161, “sentKBytesPerSec” : 0.0 }, “Total” : { “transaction” : “Total”, “sampleCount” : 20, “errorCount” : 5,
“errorPct” : 25.0, “meanResTime” : 7970.950000000001, “medianResTime”
: 115.5, “minResTime” : 0.0, “maxResTime” : 31637.0, “pct1ResTime” :
31637.0, “pct2ResTime” : 31637.0, “pct3ResTime” : 31637.0, “throughput” : 0.607810363166692, “receivedKBytesPerSec” :
1.233783809451451, “sentKBytesPerSec” : 0.0713761681355417 }, “Kibana-0” : { “transaction” : “Kibana-0”, “sampleCount” : 5,
“errorCount” : 0, “errorPct” : 0.0, “meanResTime” : 3.6,
“medianResTime” : 2.0, “minResTime” : 0.0, “maxResTime” : 12.0,
“pct1ResTime” : 12.0, “pct2ResTime” : 12.0, “pct3ResTime” : 12.0,
“throughput” : 416.6666666666667, “receivedKBytesPerSec” :
506.02213541666663, “sentKBytesPerSec” : 0.0 }, “MT – OK – 1 recipient-0” : { “transaction” : “MT – OK – 1 recipient-0”,
“sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
1.6, “medianResTime” : 1.0, “minResTime” : 0.0, “maxResTime” : 4.0, “pct1ResTime” : 4.0, “pct2ResTime” : 4.0, “pct3ResTime” : 4.0,
“throughput” : 119.04761904761904, “receivedKBytesPerSec” :
153.29706101190476, “sentKBytesPerSec” : 0.0 }, “MT – OK – 1 recipient” : { “transaction” : “MT – OK – 1 recipient”, “sampleCount”
: 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” : 244.8,
“medianResTime” : 248.0, “minResTime” : 219.0, “maxResTime” : 257.0,
“pct1ResTime” : 257.0, “pct2ResTime” : 257.0, “pct3ResTime” : 257.0,
“throughput” : 19.45525291828794, “receivedKBytesPerSec” :
30.80921692607004, “sentKBytesPerSec” : 9.138649075875486 } } { “Kibana” : { “transaction” : “Kibana”, “sampleCount” : 5, “errorCount”
: 0, “errorPct” : 0.0, “meanResTime” : 2470.0, “medianResTime” :
2423.0, “minResTime” : 2412.0, “maxResTime” : 2666.0, “pct1ResTime” : 2666.0, “pct2ResTime” : 2666.0, “pct3ResTime” : 2666.0, “throughput” : 1.8733608092918694, “receivedKBytesPerSec” : 11.436648206257026, “sentKBytesPerSec” : 0.781176821843387 }, “Total” : { “transaction” :
“Total”, “sampleCount” : 20, “errorCount” : 0, “errorPct” : 0.0,
“meanResTime” : 690.9999999999999, “medianResTime” : 148.0,
“minResTime” : 0.0, “maxResTime” : 2666.0, “pct1ResTime” : 2430.2,
“pct2ResTime” : 2654.25, “pct3ResTime” : 2666.0, “throughput” :
5.030181086519114, “receivedKBytesPerSec” : 12.769979250503019, “sentKBytesPerSec” : 1.115088971327968 }, “MT” : { “transaction” :
“MT”, “sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0,
“meanResTime” : 287.0, “medianResTime” : 288.0, “minResTime” : 284.0,
“maxResTime” : 290.0, “pct1ResTime” : 290.0, “pct2ResTime” : 290.0,
“pct3ResTime” : 290.0, “throughput” : 17.182130584192443,
“receivedKBytesPerSec” : 26.897417310996566, “sentKBytesPerSec” :
8.070903135738833 }, “Kibana-0” : { “transaction” : “Kibana-0”, “sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
3.0, “medianResTime” : 1.0, “minResTime” : 0.0, “maxResTime” : 12.0, “pct1ResTime” : 12.0, “pct2ResTime” : 12.0, “pct3ResTime” : 12.0,
“throughput” : 19.841269841269842, “receivedKBytesPerSec” :
24.104042658730158, “sentKBytesPerSec” : 0.0 }, “MT-0” : { “transaction” : “MT-0”, “sampleCount” : 5, “errorCount” : 0,
“errorPct” : 0.0, “meanResTime” : 4.0, “medianResTime” : 2.0,
“minResTime” : 1.0, “maxResTime” : 10.0, “pct1ResTime” : 10.0,
“pct2ResTime” : 10.0, “pct3ResTime” : 10.0, “throughput” :
416.6666666666667, “receivedKBytesPerSec” : 528.9713541666666, “sentKBytesPerSec” : 0.0 } } { “Total” : { “transaction” : “Total”,
“sampleCount” : 10, “errorCount” : 0, “errorPct” : 0.0, “meanResTime”
: 522.6999999999999, “medianResTime” : 511.5, “minResTime” : 488.0,
“maxResTime” : 581.0, “pct1ResTime” : 578.9, “pct2ResTime” : 581.0,
“pct3ResTime” : 581.0, “throughput” : 17.182130584192443,
“receivedKBytesPerSec” : 5.084165592783505, “sentKBytesPerSec” :
8.070903135738833 }, “MT – OK – 1 recipient” : { “transaction” : “MT – OK – 1 recipient”, “sampleCount” : 10, “errorCount” : 0, “errorPct” :
0.0, “meanResTime” : 522.6999999999999, “medianResTime” : 511.5, “minResTime” : 488.0, “maxResTime” : 581.0, “pct1ResTime” : 578.9,
“pct2ResTime” : 581.0, “pct3ResTime” : 581.0, “throughput” :
17.182130584192443, “receivedKBytesPerSec” : 5.084165592783505, “sentKBytesPerSec” : 8.070903135738833 } } { “Total” : { “transaction”
: “Total”, “sampleCount” : 332003, “errorCount” : 0, “errorPct” : 0.0,
“meanResTime” : 173.36791233813958, “medianResTime” : 148.0,
“minResTime” : 71.0, “maxResTime” : 42259.0, “pct1ResTime” : 252.0,
“pct2ResTime” : 291.0, “pct3ResTime” : 473.9800000000032, “throughput”
: 92.16552890459761, “receivedKBytesPerSec” : 61.02366073956755,
“sentKBytesPerSec” : 44.552672663843566 }, “MT – OK – 1 recipient” : {
“transaction” : “MT – OK – 1 recipient”, “sampleCount” : 332003,
“errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
173.36791233813958, “medianResTime” : 148.0, “minResTime” : 71.0, “maxResTime” : 42259.0, “pct1ResTime” : 252.0, “pct2ResTime” : 291.0,
“pct3ResTime” : 473.9800000000032, “throughput” : 92.16552890459761,
“receivedKBytesPerSec” : 61.02366073956755, “sentKBytesPerSec” :
44.552672663843566 } } { “Kibana” : { “transaction” : “Kibana”, “sampleCount” : 5, “errorCount” : 5, “errorPct” : 100.0, “meanResTime”
: 31631.2, “medianResTime” : 31632.0, “minResTime” : 31626.0,
“maxResTime” : 31635.0, “pct1ResTime” : 31635.0, “pct2ResTime” :
31635.0, “pct3ResTime” : 31635.0, “throughput” : 0.15803780264239206, “receivedKBytesPerSec” : 0.6375528932770719, “sentKBytesPerSec” : 0.0
}, “Total” : { “transaction” : “Total”, “sampleCount” : 20,
“errorCount” : 5, “errorPct” : 25.0, “meanResTime” :
7963.650000000001, “medianResTime” : 113.5, “minResTime” : 1.0, “maxResTime” : 31635.0, “pct1ResTime” : 31632.9, “pct2ResTime” :
31634.9, “pct3ResTime” : 31635.0, “throughput” : 0.6085686465433301, “receivedKBytesPerSec” : 1.2355607579722494, “sentKBytesPerSec” :
0.071465214596519 }, “Kibana-0” : { “transaction” : “Kibana-0”, “sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
1.0, “medianResTime” : 1.0, “minResTime” : 1.0, “maxResTime” : 1.0, “pct1ResTime” : 1.0, “pct2ResTime” : 1.0, “pct3ResTime” : 1.0,
“throughput” : 500.0, “receivedKBytesPerSec” : 607.421875,
“sentKBytesPerSec” : 0.0 }, “MT-0” : { “transaction” : “MT-0”,
“sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0, “meanResTime” :
7.2, “medianResTime” : 7.0, “minResTime” : 1.0, “maxResTime” : 13.0, “pct1ResTime” : 13.0, “pct2ResTime” : 13.0, “pct3ResTime” : 13.0,
“throughput” : 384.61538461538464, “receivedKBytesPerSec” :
495.4176682692308, “sentKBytesPerSec” : 0.0 }, “MT” : { “transaction” : “MT”, “sampleCount” : 5, “errorCount” : 0, “errorPct” : 0.0,
“meanResTime” : 215.2, “medianResTime” : 215.0, “minResTime” : 214.0,
“maxResTime” : 217.0, “pct1ResTime” : 217.0, “pct2ResTime” : 217.0,
“pct3ResTime” : 217.0, “throughput” : 23.041474654377883,
“receivedKBytesPerSec” : 36.49733582949309, “sentKBytesPerSec” :
10.823192684331797 } }

So it can read the whole content of every json file.
At this point I take the html file from every folder like so, and close the first <?php:

$dom = new DOMDocument;
$dom->loadHTMLFile($path4);
$xpath = new DOMXPath($dom);

$trs = $dom->getElementById("generalInfos")->getElementsByTagName("tr");

foreach($trs as $key=>$tr){
    
        foreach($tr->getElementsByTagName('td') as $td) {           
}}}}

At this point I start my table and then open a new <?php again with:

$folder = array();
    foreach($scan as $folders) {
        if($folders !== '.' && $folders !== '..'){ 
            $folder[] = $folders;
        

Then I start getting the values I need from the two files:

from the json:

$name=($data["MT"]->transaction);
$req=($data["Total"]->sampleCount);   
$tp=($data["Total"]->throughput);
$roundNumber = round($tp, 3);
$err=($data["Total"]->errorCount);

and from the html:

$st = $xpath->query('//div/table/tr/td')->item(3);
$st1 = str_replace('"','',$st->textContent);                
$et = $xpath->query('//div/table/tr/td')->item(5);
$et1 = str_replace('"','',$et->textContent);

$st2 = strtotime($st1); 
$stD = date('d/m/Y h:i:s', $st2);
$SThour=date_create('h:i:s',$st2);
    
$et2 = strtotime($et1); 
$etD = date('d/m/Y h:i:s', $et2);
$EThour=date_create('h:i:s',$et2);
                
$diff = date('h:i:s', ($SThour -$EThour));
$diff1 = date('h:i:s', $diff)/ 30;
$diff2 = number_format((float)$diff1, 3, '.', '');

I close the second <?php and I go to populate the table:

<tr>
            <td align="center"><?php echo $folders;?></td>
            <td align="center"><?php echo $name;?></td>
            <td align="center"><?php echo $stD;?></td>
            <td align="center"><?php echo $diff2;?></td>
            <td align="center"><?php echo $req;?></td>
            <td align="center"><?php echo $roundNumber;?></td>
            <td align="center"><?php echo $err;?></td>
            <td><a href="<?php echo $path3.$folders."/" ?>" target =’_blank’>LINK</a></h1></td>
            
            
</tr>

What I get is a table that actually shows as many rows as the folders in the path, but I think that’s just because the first and the last work just fine: every row starts with a list and ends with a link related to each different folder in the path.
As per the rest of the data, as you can see from this screenshot (sorry for the quality), it all comes from the same folder, clearly.

So please, how do i show the data in the table from the 2 files of each folder, instead of just from one?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật