Drop-down element list rendered as a calc element in an HTML table.

lpro87

New Member
Dear Fabrik specialists, I can not display data from a repeating group in a table. I am using Joomla 3.10 and Fabrik 3.1+.
The table should grow on its own. But all the data gets into one cell through quotation marks and a comma.
There is a repeating group of 4 elements:
1) Dropdown list (monitoring_ocenka_34_repeat___LekarstPrepar_lek)
2) Simple field (monitoring_ocenka_34_repeat___FaktichOstat_lek)
3) Simple field (monitoring_ocenka_34_repeat___OstatokJurnal_lek)
4) Calc element (monitoring_evaluation_34_repeat___DifferenceRemaining_curs)

There is also Calc element (monitoring_ocenka___tabs_lec) where this repeating group is displayed in an HTML table.
Here is the content of this element:

Code:
$myid = '{monitoring_ocenka_34_repeat___LekarstPrepar_lek}';
$myid2 = '{monitoring_ocenka_34_repeat___FaktichOstat_lek}';
$myid3 = '{monitoring_ocenka_34_repeat___OstatokJurnal_lek}';
$myid4 = '{monitoring_ocenka_34_repeat___RaznicOstat_lek}';

$myids = json_decode($myid);
$foo = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___LekarstPrepar_lek'], true);

$myids2 = json_decode($myid2);
$foo2 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___FaktichOstat_lek'], true);

$myids3 = json_decode($myid3);
$foo3 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___OstatokJurnal_lek'], true);

$myids4 = json_decode($myid4);
$foo4 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___RaznicOstat_lek'], true);

$am1 = "'" . implode("','", $foo) . "'";
$am2 = "'" . implode("','", $foo2) . "'";
$am3 = "'" . implode("','", $foo3) . "'";
$am4 = "'" . implode("','", $foo4) . "'";

$arr=array(
        "Name LS"=> array($am1),
        "FO"=> array($am2),
        "OJ"=> array($am3),
        "SUMM"=> array($am4),
    );

$mytable = '<table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><b>Name LS</b></td>
<td style="vertical-align: top;"><b>FO</b></td>
<td style="vertical-align: top;"><b>OJ</b></td>
<td style="vertical-align: top;"><b>SUMM</b></td>
</tr>';

foreach ($arr as $key => $value) {
  
        $mytable .= "";
      
    }

for ($i=0; $i <= count($value)-1 ; $i++) {
  
    $mytable .= '<tr>';
        foreach ($arr as $key => $value) {
        $mytable .= "<td>$value[$i]</td>";   
    }
    $mytable .= '</tr>';
    }

 
    $mytable .= '</tbody>';
    $mytable .= '</table>';
    return $mytable;
 

Attachments

  • photo_2023-06-30_20-21-10.jpg
    photo_2023-06-30_20-21-10.jpg
    52.4 KB · Views: 27
Last edited:
Okay, so two issues.

From what I can see your code is doing what you are telling it to do.

I'm not sure what the $myids = json_decode($myid); are doing as they don't seem to be referenced anywhere.

Are you just trying to put this data in a table? Have you seen the alternative template for repeat groups? If you go to your repeat group, click repeat and change template from list to table..... this may do what you are trying to achieve.

Let's get that bit sorted before the second issue.
 
Code:
$arr=array(
        "Name LS"=> array('red','yellow','black',),
        "FO"=> array('red','yellow','black',),
        "OJ"=> array('red','yellow','black',),
        "SUMM"=> array('red','yellow','black',),
    );

$mytable = '<table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><b>Name LS</b></td>
<td style="vertical-align: top;"><b>FO</b></td>
<td style="vertical-align: top;"><b>OJ</b></td>
<td style="vertical-align: top;"><b>SUMM</b></td>
</tr>';

foreach ($arr as $key => $value) {
        $mytable .= "";
  
    }

for ($i=0; $i <= count($value)-1 ; $i++) {
    $mytable .= '<tr>';
        foreach ($arr as $key => $value) {
        $mytable .= "<td>$value[$i]</td>";
    }
    $mytable .= '</tr>';
    }

    $mytable .= '</tbody>';
    $mytable .= '</table>';
    return $mytable;
Okay, so two issues.

From what I can see your code is doing what you are telling it to do.

I'm not sure what the $myids = json_decode($myid); are doing as they don't seem to be referenced anywhere.

Are you just trying to put this data in a table? Have you seen the alternative template for repeat groups? If you go to your repeat group, click repeat and change template from list to table..... this may do what you are trying to achieve.

Let's get that bit sorted before the second issue.
The data that I can get from the repeating group is separated by commas from each element (For example: 1,2,3,4,5). There are no problems in this.
I wanted to make this data more presentable in the form of a table. And the table should grow as you add repetitions in the group. If I just put ' red ' ,' yellow ',' black' into the $arr array, then everything works fine. Here is the first part of the code is not working correctly.
 

Attachments

  • photo_2023-06-30_23-22-30.jpg
    photo_2023-06-30_23-22-30.jpg
    38.1 KB · Views: 14
Last edited:
"If I just put ' red ' ,' yellow ',' black' into the $arr array, then everything works fine"

Can you do a screenshot of this so I can see what you are trying to achieve.
 
"If I just put ' red ' ,' yellow ',' black' into the $arr array, then everything works fine"

Can you do a screenshot of this so I can see what you are trying to achieve.
 

Attachments

  • photo_2023-06-30_23-22-30.jpg
    photo_2023-06-30_23-22-30.jpg
    38.1 KB · Views: 19
Try this.... I think this is what you want.

Code:
$myid = '{monitoring_ocenka_34_repeat___LekarstPrepar_lek}';
$myid2 = '{monitoring_ocenka_34_repeat___FaktichOstat_lek}';
$myid3 = '{monitoring_ocenka_34_repeat___OstatokJurnal_lek}';
$myid4 = '{monitoring_ocenka_34_repeat___RaznicOstat_lek}';

$arr=array(
        "Name LS"=> $myid,
        "FO"=> $myid2,
        "OJ"=> $myid3,
        "SUMM"=> $myid4,
    );


$mytable = '<table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><b>Name LS</b></td>
<td style="vertical-align: top;"><b>FO</b></td>
<td style="vertical-align: top;"><b>OJ</b></td>
<td style="vertical-align: top;"><b>SUMM</b></td>
</tr>';

//echo '<pre>'; print_r($arr); exit;

foreach ($arr as $key => $value) {
        $mytable .= "";
     
    }

for ($i=0; $i <= count($value)-1 ; $i++) {
    $mytable .= '<tr>';
        foreach ($arr as $key => $value) {
        $mytable .= "<td>$value[$i]</td>";  
    }
    $mytable .= '</tr>';
    }

    $mytable .= '</tbody>';
    $mytable .= '</table>';
    return $mytable;
 
Try this.... I think this is what you want.

Code:
$myid = '{monitoring_ocenka_34_repeat___LekarstPrepar_lek}';
$myid2 = '{monitoring_ocenka_34_repeat___FaktichOstat_lek}';
$myid3 = '{monitoring_ocenka_34_repeat___OstatokJurnal_lek}';
$myid4 = '{monitoring_ocenka_34_repeat___RaznicOstat_lek}';

$arr=array(
        "Name LS"=> $myid,
        "FO"=> $myid2,
        "OJ"=> $myid3,
        "SUMM"=> $myid4,
    );


$mytable = '<table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><b>Name LS</b></td>
<td style="vertical-align: top;"><b>FO</b></td>
<td style="vertical-align: top;"><b>OJ</b></td>
<td style="vertical-align: top;"><b>SUMM</b></td>
</tr>';

//echo '<pre>'; print_r($arr); exit;

foreach ($arr as $key => $value) {
        $mytable .= "";
    
    }

for ($i=0; $i <= count($value)-1 ; $i++) {
    $mytable .= '<tr>';
        foreach ($arr as $key => $value) {
        $mytable .= "<td>$value[$i]</td>"; 
    }
    $mytable .= '</tr>';
    }

    $mytable .= '</tbody>';
    $mytable .= '</table>';
    return $mytable;
I tried. Only 1 line is filled. Subsequent ones do not form an array of data.
 

Attachments

  • photo_2023-07-01_01-41-20.jpg
    photo_2023-07-01_01-41-20.jpg
    52 KB · Views: 21
The data doesn't look the same either.

I've only be able to test in Fabrik 4, I'll try and test in Fabrik 3 later.

A similar setup seemed okay on Fabrik 4, although I haven't used dropdown or calc elements, only field.

upload_2023-6-30_22-20-4.png
 
The data doesn't look the same either.

I've only be able to test in Fabrik 4, I'll try and test in Fabrik 3 later.

A similar setup seemed okay on Fabrik 4, although I haven't used dropdown or calc elements, only field.

View attachment 20745
I duplicated simple fields on pure joomla 3.10.11 and Fabrik 3.1+
Does not work. Outputs only the first repeat of the group.
 

Attachments

  • nonameimg.jpg
    nonameimg.jpg
    46 KB · Views: 25
I do not know what it is connected with, but in this form the code works. Perhaps this will be useful to someone, and perhaps this is fundamentally not true. The calc element was replaced with a simple field. Thank you cat Felix.
But there is one caveat, the calc element does not work in a repeating group, it does not get into the array, no matter what methods you come up with. It just isn't output by any method. Maybe someone has a solution?


Code:
$myid = '{monitoring_ocenka_34_repeat___LekarstPrepar_lek}';
$myid2 = '{monitoring_ocenka_34_repeat___FaktichOstat_lek}';
$myid3 = '{monitoring_ocenka_34_repeat___OstatokJurnal_lek}';
$myid4 = '{monitoring_ocenka_34_repeat___RaznicOstat_lek}';

$foo = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___LekarstPrepar_lek'], true);
$foo2 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___FaktichOstat_lek'], true);
$foo3 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___OstatokJurnal_lek'], true);
$foo4 = FabrikWorker::JSONtoData($data['monitoring_ocenka_34_repeat___RaznicOstat_lek'], true);

$arr=array(
        "Arrname"=> $data['monitoring_ocenka_34_repeat___LekarstPrepar_lek'],
        "FO"=> $data['monitoring_ocenka_34_repeat___FaktichOstat_lek'],
        "OJ"=> $data['monitoring_ocenka_34_repeat___OstatokJurnal_lek'],
        "SUMM"=> $data['monitoring_ocenka_34_repeat___RaznicOstat_lek'],

    );

$mytable = '<table style="text-align: center; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><b>Arrname</b></td>
<td style="vertical-align: top;"><b>FO</b></td>
<td style="vertical-align: top;"><b>OJ</b></td>
<td style="vertical-align: top;"><b>SUMM</b></td>
</tr>';

foreach ($arr as $key => $value) {
   
        $mytable .= "";
       
    }

for ($i=0; $i <= count($value)-1 ; $i++) {
   
    $mytable .= '<tr>';
        foreach ($arr as $key => $value) {
        $mytable .= "<td>$value[$i]</td>";    
    }
    $mytable .= '</tr>';
    }

 
    $mytable .= '</tbody>';
    $mytable .= '</table>';
    return $mytable;
 

Attachments

  • photo_2023-07-01_16-48-28.jpg
    photo_2023-07-01_16-48-28.jpg
    52.4 KB · Views: 19
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top